@@ -1577,41 +1577,52 @@ 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+ $ controllers = [];
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+ $ routeKey = key ($ route ['route ' ]);
1592+ $ controller = $ this ->getControllerName ($ route ['route ' ][$ routeKey ]);
1593+ if ($ controller !== null ) {
1594+ $ controllers [] = $ controller ;
1595+ }
1596+ }
15971597 }
15981598 } else {
15991599 $ routes = $ this ->getRoutes ($ verb );
1600- }
1601-
1602- $ controllers = [];
16031600
1604- foreach ($ routes as $ handler ) {
1605- if (! is_string ($ handler )) {
1606- continue ;
1601+ foreach ($ routes as $ handler ) {
1602+ $ controller = $ this ->getControllerName ($ handler );
1603+ if ($ controller !== null ) {
1604+ $ controllers [] = $ controller ;
1605+ }
16071606 }
1607+ }
16081608
1609- [$ controller ] = explode (':: ' , $ handler , 2 );
1609+ return array_unique ($ controllers );
1610+ }
16101611
1611- $ controllers [] = $ controller ;
1612+ /**
1613+ * @param Closure|string $handler Handler
1614+ *
1615+ * @return string|null Controller classname
1616+ */
1617+ private function getControllerName ($ handler )
1618+ {
1619+ if (! is_string ($ handler )) {
1620+ return null ;
16121621 }
16131622
1614- return array_unique ($ controllers );
1623+ [$ controller ] = explode (':: ' , $ handler , 2 );
1624+
1625+ return $ controller ;
16151626 }
16161627
16171628 /**
0 commit comments