Skip to content

Commit

Permalink
Merge pull request #5651 from iRedds/feature/command-routes-closure
Browse files Browse the repository at this point in the history
Feature: "spark routes" command shows routes with closure.
  • Loading branch information
samsonasik authored Feb 5, 2022
2 parents ec146df + 54438e3 commit 1c455b5
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 2 deletions.
5 changes: 3 additions & 2 deletions system/Commands/Utilities/Routes.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

namespace CodeIgniter\Commands\Utilities;

use Closure;
use CodeIgniter\CLI\BaseCommand;
use CodeIgniter\CLI\CLI;
use CodeIgniter\Commands\Utilities\Routes\AutoRouteCollector;
Expand Down Expand Up @@ -92,11 +93,11 @@ public function run(array $params)

foreach ($routes as $route => $handler) {
// filter for strings, as callbacks aren't displayable
if (is_string($handler)) {
if (is_string($handler) || $handler instanceof Closure) {
$tbody[] = [
strtoupper($method),
$route,
$handler,
is_string($handler) ? $handler : '(Closure)',
];
}
}
Expand Down
1 change: 1 addition & 0 deletions tests/_support/Config/Routes.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,4 @@

// This is a simple file to include for testing the RouteCollection class.
$routes->add('testing', 'TestController::index', ['as' => 'testing-index']);
$routes->get('closure', static fn () => 'closure test');
1 change: 1 addition & 0 deletions tests/system/Commands/CommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ public function testRoutesCommand()
{
command('routes');

$this->assertStringContainsString('| (Closure)', $this->getBuffer());
$this->assertStringContainsString('| Route', $this->getBuffer());
$this->assertStringContainsString('| testing', $this->getBuffer());
$this->assertStringContainsString('\\TestController::index', $this->getBuffer());
Expand Down

0 comments on commit 1c455b5

Please sign in to comment.