Skip to content

Commit 74bbf2b

Browse files
committed
fix: getRegisteredControllers() may not return all controllers
1 parent 680ea61 commit 74bbf2b

1 file changed

Lines changed: 13 additions & 12 deletions

File tree

system/Router/RouteCollection.php

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1577,31 +1577,32 @@ public function setPrioritize(bool $enabled = true)
15771577
* Get all controllers in Route Handlers
15781578
*
15791579
* @param string|null $verb HTTP verb. `'*'` returns all controllers in any verb.
1580+
*
1581+
* @return array<int, string> controller name list
1582+
* @phpstan-return list<string>
15801583
*/
15811584
public function getRegisteredControllers(?string $verb = '*'): array
15821585
{
1583-
$routes = [];
1586+
$handlers = [];
15841587

15851588
if ($verb === '*') {
1586-
$rawRoutes = [];
1587-
15881589
foreach ($this->defaultHTTPMethods as $tmpVerb) {
1589-
$rawRoutes = array_merge($rawRoutes, $this->routes[$tmpVerb]);
1590-
}
1591-
1592-
foreach ($rawRoutes as $route) {
1593-
$key = key($route['route']);
1594-
$handler = $route['route'][$key];
1595-
1596-
$routes[$key] = $handler;
1590+
foreach ($this->routes[$tmpVerb] as $route) {
1591+
$key = key($route['route']);
1592+
$handlers[] = $route['route'][$key];
1593+
}
15971594
}
15981595
} else {
15991596
$routes = $this->getRoutes($verb);
1597+
1598+
foreach ($routes as $handler) {
1599+
$handlers[] = $handler;
1600+
}
16001601
}
16011602

16021603
$controllers = [];
16031604

1604-
foreach ($routes as $handler) {
1605+
foreach ($handlers as $handler) {
16051606
if (! is_string($handler)) {
16061607
continue;
16071608
}

0 commit comments

Comments
 (0)