Skip to content

Commit

Permalink
Merge pull request #8957 from kenjis/fix-RouteCollection-TypeError
Browse files Browse the repository at this point in the history
fix: TypeError in DefinedRouteCollector::collect()
  • Loading branch information
kenjis committed Jun 17, 2024
2 parents 3e2aefb + 4e35d38 commit 7aced76
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
4 changes: 4 additions & 0 deletions system/Router/DefinedRouteCollector.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,10 @@ public function collect(): Generator
$routes = $this->routeCollection->getRoutes($method);

foreach ($routes as $route => $handler) {
// The route key should be a string, but it is stored as an array key,
// it might be an integer.
$route = (string) $route;

if (is_string($handler) || $handler instanceof Closure) {
if ($handler instanceof Closure) {
$view = $this->routeCollection->getRoutesOptions($route, $method)['view'] ?? false;
Expand Down
14 changes: 14 additions & 0 deletions tests/system/Router/DefinedRouteCollectorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,10 @@ public function testCollect(): void
{
$routes = $this->createRouteCollection();
$routes->get('journals', 'Blogs');
$routes->get('100', 'Home::index');
$routes->get('product/(:num)', 'Catalog::productLookupByID/$1');
$routes->get('feed', static fn () => 'A Closure route.');
$routes->get('200', static fn () => 'A Closure route.');
$routes->view('about', 'pages/about');

$collector = new DefinedRouteCollector($routes);
Expand All @@ -69,6 +71,12 @@ public function testCollect(): void
'name' => 'journals',
'handler' => '\App\Controllers\Blogs',
],
[
'method' => 'GET',
'route' => '100',
'name' => '100',
'handler' => '\App\Controllers\Home::index',
],
[
'method' => 'GET',
'route' => 'product/([0-9]+)',
Expand All @@ -81,6 +89,12 @@ public function testCollect(): void
'name' => 'feed',
'handler' => '(Closure)',
],
[
'method' => 'GET',
'route' => '200',
'name' => '200',
'handler' => '(Closure)',
],
[
'method' => 'GET',
'route' => 'about',
Expand Down

0 comments on commit 7aced76

Please sign in to comment.