Skip to content

Commit 7aced76

Browse files
authored
Merge pull request #8957 from kenjis/fix-RouteCollection-TypeError
fix: TypeError in DefinedRouteCollector::collect()
2 parents 3e2aefb + 4e35d38 commit 7aced76

File tree

2 files changed

+18
-0
lines changed

2 files changed

+18
-0
lines changed

system/Router/DefinedRouteCollector.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,10 @@ public function collect(): Generator
3838
$routes = $this->routeCollection->getRoutes($method);
3939

4040
foreach ($routes as $route => $handler) {
41+
// The route key should be a string, but it is stored as an array key,
42+
// it might be an integer.
43+
$route = (string) $route;
44+
4145
if (is_string($handler) || $handler instanceof Closure) {
4246
if ($handler instanceof Closure) {
4347
$view = $this->routeCollection->getRoutesOptions($route, $method)['view'] ?? false;

tests/system/Router/DefinedRouteCollectorTest.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,10 @@ public function testCollect(): void
5050
{
5151
$routes = $this->createRouteCollection();
5252
$routes->get('journals', 'Blogs');
53+
$routes->get('100', 'Home::index');
5354
$routes->get('product/(:num)', 'Catalog::productLookupByID/$1');
5455
$routes->get('feed', static fn () => 'A Closure route.');
56+
$routes->get('200', static fn () => 'A Closure route.');
5557
$routes->view('about', 'pages/about');
5658

5759
$collector = new DefinedRouteCollector($routes);
@@ -69,6 +71,12 @@ public function testCollect(): void
6971
'name' => 'journals',
7072
'handler' => '\App\Controllers\Blogs',
7173
],
74+
[
75+
'method' => 'GET',
76+
'route' => '100',
77+
'name' => '100',
78+
'handler' => '\App\Controllers\Home::index',
79+
],
7280
[
7381
'method' => 'GET',
7482
'route' => 'product/([0-9]+)',
@@ -81,6 +89,12 @@ public function testCollect(): void
8189
'name' => 'feed',
8290
'handler' => '(Closure)',
8391
],
92+
[
93+
'method' => 'GET',
94+
'route' => '200',
95+
'name' => '200',
96+
'handler' => '(Closure)',
97+
],
8498
[
8599
'method' => 'GET',
86100
'route' => 'about',

0 commit comments

Comments
 (0)