Skip to content

Commit

Permalink
Show routes in the order they are set
Browse files Browse the repository at this point in the history
  • Loading branch information
natanfelles committed Aug 20, 2022
1 parent aaad6cd commit 20bd30c
Showing 1 changed file with 6 additions and 9 deletions.
15 changes: 6 additions & 9 deletions src/Debug/RoutingCollector.php
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,7 @@ protected function renderRouteCollectionsTable(RouteCollection $collection) : st
<table>
<thead>
<tr>
<th>#</th>
<th>Method</th>
<th>Path</th>
<th>Action</th>
Expand All @@ -248,8 +249,9 @@ protected function renderRouteCollectionsTable(RouteCollection $collection) : st
</tr>
</thead>
<tbody>
<?php foreach ($this->getRoutes($collection) as $route): ?>
<?php foreach ($this->getRoutes($collection) as $index => $route): ?>
<tr<?= $route['matched'] ? ' class="active" title="Matched Route"' : '' ?>>
<td><?= ++$index ?></td>
<td><?= \htmlentities($route['method']) ?></td>
<td><?= $this->toCodeBrackets(\htmlentities($route['path'])) ?></td>
<td><?= \htmlentities($route['action']) ?></td>
Expand All @@ -271,7 +273,9 @@ protected function renderRouteCollectionsTable(RouteCollection $collection) : st
protected function getRoutes(RouteCollection $collection) : array
{
$result = [];
foreach ($collection->routes as $method => $routes) {
$collectionRoutes = $collection->routes;
\ksort($collectionRoutes);
foreach ($collectionRoutes as $method => $routes) {
foreach ($routes as $route) {
$result[] = [
'method' => $method,
Expand All @@ -283,13 +287,6 @@ protected function getRoutes(RouteCollection $collection) : array
];
}
}
\usort($result, static function ($str1, $str2) {
$cmp = \strcmp($str1['path'], $str2['path']);
if ($cmp === 0) {
$cmp = \strcmp($str1['method'], $str2['method']);
}
return $cmp;
});
return $result;
}

Expand Down

0 comments on commit 20bd30c

Please sign in to comment.