-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathRouteList.php
More file actions
37 lines (30 loc) · 1.01 KB
/
RouteList.php
File metadata and controls
37 lines (30 loc) · 1.01 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
<?php
namespace Rareloop\Hatchet\Commands;
use Rareloop\Hatchet\Commands\Command;
use Rareloop\Router\Router;
use Symfony\Component\Console\Attribute\AsCommand;
use Symfony\Component\Console\Helper\Table;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
#[AsCommand(
name: 'route:list',
description: 'List all registered routes'
)]
class RouteList extends Command
{
protected function execute(InputInterface $input, OutputInterface $output): int
{
$router = $this->app->get(Router::class);
$rows = collect($router->getRoutes())->map(function ($route) {
return [
strtoupper(implode('|', $route->getMethods())),
$route->getUri(),
$route->getName(),
$route->getActionName(),
];
})->toArray();
$table = new Table($output);
$table->setHeaders(['Method', 'URI', 'Name', 'Action'])->setRows($rows);
$table->render();
}
}