Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: TypeError in DefinedRouteCollector::collect() #8957

Merged
merged 2 commits into from
Jun 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading