Skip to content

Commit 1c455b5

Browse files
authored
Merge pull request #5651 from iRedds/feature/command-routes-closure
Feature: "spark routes" command shows routes with closure.
2 parents ec146df + 54438e3 commit 1c455b5

File tree

3 files changed

+5
-2
lines changed

3 files changed

+5
-2
lines changed

system/Commands/Utilities/Routes.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
namespace CodeIgniter\Commands\Utilities;
1313

14+
use Closure;
1415
use CodeIgniter\CLI\BaseCommand;
1516
use CodeIgniter\CLI\CLI;
1617
use CodeIgniter\Commands\Utilities\Routes\AutoRouteCollector;
@@ -92,11 +93,11 @@ public function run(array $params)
9293

9394
foreach ($routes as $route => $handler) {
9495
// filter for strings, as callbacks aren't displayable
95-
if (is_string($handler)) {
96+
if (is_string($handler) || $handler instanceof Closure) {
9697
$tbody[] = [
9798
strtoupper($method),
9899
$route,
99-
$handler,
100+
is_string($handler) ? $handler : '(Closure)',
100101
];
101102
}
102103
}

tests/_support/Config/Routes.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,4 @@
1313

1414
// This is a simple file to include for testing the RouteCollection class.
1515
$routes->add('testing', 'TestController::index', ['as' => 'testing-index']);
16+
$routes->get('closure', static fn () => 'closure test');

tests/system/Commands/CommandTest.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,7 @@ public function testRoutesCommand()
110110
{
111111
command('routes');
112112

113+
$this->assertStringContainsString('| (Closure)', $this->getBuffer());
113114
$this->assertStringContainsString('| Route', $this->getBuffer());
114115
$this->assertStringContainsString('| testing', $this->getBuffer());
115116
$this->assertStringContainsString('\\TestController::index', $this->getBuffer());

0 commit comments

Comments
 (0)