Skip to content

Commit

Permalink
refactor: use DefinedRouteCollector in DebugBar
Browse files Browse the repository at this point in the history
  • Loading branch information
kenjis committed Jul 4, 2023
1 parent 4bf6b24 commit d12c63b
Showing 1 changed file with 13 additions and 29 deletions.
42 changes: 13 additions & 29 deletions system/Debug/Toolbar/Collectors/Routes.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

namespace CodeIgniter\Debug\Toolbar\Collectors;

use CodeIgniter\Router\DefinedRouteCollector;
use Config\Services;
use ReflectionException;
use ReflectionFunction;
Expand Down Expand Up @@ -55,9 +56,6 @@ public function display(): array
$rawRoutes = Services::routes(true);
$router = Services::router(null, null, true);

// Matched Route
$route = $router->getMatchedRoute();

// Get our parameters
// Closure routes
if (is_callable($router->controllerName())) {
Expand Down Expand Up @@ -100,32 +98,18 @@ public function display(): array
];

// Defined Routes
$routes = [];
$methods = [
'get',
'head',
'post',
'patch',
'put',
'delete',
'options',
'trace',
'connect',
'cli',
];

foreach ($methods as $method) {
$raw = $rawRoutes->getRoutes($method);

foreach ($raw as $route => $handler) {
// filter for strings, as callbacks aren't displayable
if (is_string($handler)) {
$routes[] = [
'method' => strtoupper($method),
'route' => $route,
'handler' => $handler,
];
}
$routes = [];

$definedRouteCollector = new DefinedRouteCollector($rawRoutes);

foreach ($definedRouteCollector->collect() as $route) {
// filter for strings, as callbacks aren't displayable
if ($route['handler'] !== '(Closure)') {
$routes[] = [
'method' => strtoupper($route['method']),
'route' => $route['route'],
'handler' => $route['handler'],
];
}
}

Expand Down

0 comments on commit d12c63b

Please sign in to comment.