router = $router; } /** * Gibt alle registrierten Routen als JSON zurück. * * @param Request $request * @param array $params * @return Response */ public function json(Request $request, array $params): Response { $routes = []; foreach ($this->router->getRoutes() as $method => $paths) { foreach ($paths as $path => $route) { $routes[] = [ 'method' => $method, 'path' => $path, 'name' => $route['name'] ?? null, 'middleware_count' => isset($route['middleware']) ? count($route['middleware']) : 0, ]; } } return (new Response())->withJson($routes, 200, JSON_PRETTY_PRINT); } /** * Gibt alle registrierten Routen als HTML-Tabelle zurück. * * @param Request $request * @param array $params * @return Response */ public function html(Request $request, array $params): Response { $routes = []; foreach ($this->router->getRoutes() as $method => $paths) { foreach ($paths as $path => $route) { $routes[] = [ 'method' => $method, 'path' => $path, 'name' => $route['name'] ?? '', 'middleware_count' => isset($route['middleware']) ? count($route['middleware']) : 0, ]; } } $html = '

Routen-Übersicht

'; foreach ($routes as $route) { $link = '' . htmlspecialchars($route['path'], ENT_QUOTES, 'UTF-8') . ''; $html .= ''; } $html .= '
MethodPathNameMiddleware
' . htmlspecialchars($route['method'], ENT_QUOTES, 'UTF-8') . '' . $link . '' . htmlspecialchars($route['name'], ENT_QUOTES, 'UTF-8') . '' . (int)$route['middleware_count'] . '
'; return (new Response())->withHtml($html); } }