forked from doppar/framework
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRouteListCommand.php
More file actions
76 lines (61 loc) · 1.96 KB
/
RouteListCommand.php
File metadata and controls
76 lines (61 loc) · 1.96 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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
<?php
namespace Phaseolies\Console\Commands;
use RuntimeException;
use Phaseolies\Console\Schedule\Command;
use Phaseolies\Support\Facades\Pool;
class RouteListCommand extends Command
{
/**
* The name of the console command.
*
* @var string
*/
protected $name = 'route:list';
/**
* The description of the console command.
*
* @var string
*/
protected $description = 'Display all registered routes';
/**
* Execute the console command.
*
* @return int
*/
public function handle(): int
{
return $this->executeWithTiming(function () {
$cachePath = storage_path('framework/cache/routes.php');
if (!file_exists($cachePath)) {
Pool::call('route:cache');
}
$routesData = require $cachePath;
if (!isset($routesData['routes'])) {
throw new RuntimeException("Invalid route cache format.");
}
$table = $this->createTable();
$table->setHeaders(['Method', 'URI', 'Controller', 'Action', 'Middleware']);
foreach ($routesData['routes'] as $method => $routes) {
foreach ($routes as $uri => $handler) {
if (is_array($handler)) {
[$controller, $action] = $handler;
} else {
$controller = $handler;
$action = '__invoke';
}
$middlewares = $routesData['routeMiddlewares'][$method][$uri] ?? [];
$middlewares = implode(', ', $middlewares);
$table->addRow([
$method,
$uri,
$controller,
$action,
$middlewares,
]);
}
}
$table->render();
return Command::SUCCESS;
});
}
}