54 lines
1.9 KiB
PHP
54 lines
1.9 KiB
PHP
<?php
|
|
|
|
namespace App\Controller;
|
|
|
|
use MyCodebox\MariaCore\Http\Request;
|
|
use MyCodebox\MariaCore\Http\Response;
|
|
|
|
class RoutesController
|
|
{
|
|
protected $router;
|
|
|
|
public function __construct($router)
|
|
{
|
|
$this->router = $router;
|
|
}
|
|
|
|
public function json(Request $request, array $params)
|
|
{
|
|
$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);
|
|
}
|
|
|
|
public function html(Request $request, array $params)
|
|
{
|
|
$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 = '<h1>Routen-Übersicht</h1><table border="1" cellpadding="5" style="border-collapse:collapse"><tr><th>Method</th><th>Path</th><th>Name</th><th>Middleware</th></tr>';
|
|
foreach ($routes as $route) {
|
|
$link = '<a href="' . htmlspecialchars($route['path']) . '">' . htmlspecialchars($route['path']) . '</a>';
|
|
$html .= '<tr><td>' . htmlspecialchars($route['method']) . '</td><td>' . $link . '</td><td>' . htmlspecialchars($route['name']) . '</td><td>' . $route['middleware_count'] . '</td></tr>';
|
|
}
|
|
$html .= '</table>';
|
|
return (new Response())->withHtml($html);
|
|
}
|
|
}
|