diff --git a/system/Commands/Utilities/Routes.php b/system/Commands/Utilities/Routes.php index 210d1e11c5f7..78c7f1c8411f 100644 --- a/system/Commands/Utilities/Routes.php +++ b/system/Commands/Utilities/Routes.php @@ -13,6 +13,9 @@ use CodeIgniter\CLI\BaseCommand; use CodeIgniter\CLI\CLI; +use CodeIgniter\Commands\Utilities\Routes\ControllerFinder; +use CodeIgniter\Commands\Utilities\Routes\ControllerMethodReader; +use CodeIgniter\Router\RouteCollection; use Config\Services; /** @@ -101,6 +104,10 @@ public function run(array $params) } } + if ($collection->shouldAutoRoute()) { + $tbody = array_merge($tbody, $this->getAutoRoutes($collection)); + } + $thead = [ 'Method', 'Route', @@ -109,4 +116,31 @@ public function run(array $params) CLI::table($tbody, $thead); } + + private function getAutoRoutes(RouteCollection $collection): array + { + $defaultNamespace = $collection->getDefaultNamespace(); + $finder = new ControllerFinder($defaultNamespace); + $reader = new ControllerMethodReader($defaultNamespace); + + $tbody = []; + + foreach ($finder->find() as $class) { + $output = $reader->read( + $class, + $collection->getDefaultController(), + $collection->getDefaultMethod() + ); + + foreach ($output as $item) { + $tbody[] = [ + 'auto', + $item['route'], + $item['handler'], + ]; + } + } + + return $tbody; + } }