1
|
|
|
<?php declare(strict_types = 1); |
2
|
|
|
|
3
|
|
|
namespace Venta\Framework\Commands; |
4
|
|
|
|
5
|
|
|
use Symfony\Component\Console\Helper\Table; |
6
|
|
|
use Symfony\Component\Console\Input\InputInterface; |
7
|
|
|
use Symfony\Component\Console\Output\OutputInterface; |
8
|
|
|
use Venta\Console\Command; |
9
|
|
|
use Venta\Contracts\Routing\RouteCollector; |
10
|
|
|
|
11
|
|
|
/** |
12
|
|
|
* Class Route |
13
|
|
|
* |
14
|
|
|
* @package Venta\Commands |
15
|
|
|
*/ |
16
|
|
|
class Routes extends Command |
17
|
|
|
{ |
18
|
|
|
|
19
|
|
|
/** |
20
|
|
|
* @var RouteCollector |
21
|
|
|
*/ |
22
|
|
|
protected $collector; |
23
|
|
|
|
24
|
|
|
/** |
25
|
|
|
* Routes constructor. |
26
|
|
|
* |
27
|
|
|
* @param RouteCollector $collector |
28
|
|
|
*/ |
29
|
1 |
|
public function __construct(RouteCollector $collector) |
30
|
|
|
{ |
31
|
1 |
|
parent::__construct(); |
32
|
1 |
|
$this->collector = $collector; |
33
|
1 |
|
} |
34
|
|
|
|
35
|
|
|
/** |
36
|
|
|
* @inheritDoc |
37
|
|
|
*/ |
38
|
1 |
|
public function description(): string |
39
|
|
|
{ |
40
|
1 |
|
return 'Lists application routes'; |
41
|
|
|
} |
42
|
|
|
|
43
|
|
|
/** |
44
|
|
|
* @inheritDoc |
45
|
|
|
*/ |
46
|
1 |
|
public function handle(InputInterface $input, OutputInterface $output) |
47
|
|
|
{ |
48
|
1 |
|
$routes = $this->collector->getRoutes(); |
49
|
1 |
|
if (count($routes) == 0) { |
50
|
1 |
|
$this->writeln('<error>Application has no routes.</error>'); |
51
|
|
|
} else { |
52
|
|
|
$table = new Table($output); |
53
|
|
|
$table->setHeaders(['Methods', 'Path', 'Action', 'Name', 'Host', 'Scheme', 'Middlewares']); |
54
|
|
|
foreach ($routes as $route) { |
55
|
|
|
$table->addRow([ |
56
|
|
|
join(',', $route->getMethods()), |
57
|
|
|
$route->getPath(), |
58
|
|
|
is_string($route->getCallable()) ? $route->getCallable() : get_class($route->getCallable()), |
59
|
|
|
$route->getName(), |
60
|
|
|
$route->getHost(), |
61
|
|
|
$route->getScheme(), |
62
|
|
|
join(',', array_keys($route->getMiddlewares())), |
63
|
|
|
]); |
64
|
|
|
} |
65
|
|
|
$table->render(); |
66
|
|
|
} |
67
|
1 |
|
} |
68
|
|
|
|
69
|
|
|
/** |
70
|
|
|
* @inheritDoc |
71
|
|
|
*/ |
72
|
1 |
|
public function signature(): string |
73
|
|
|
{ |
74
|
1 |
|
return 'route:list'; |
75
|
|
|
} |
76
|
|
|
|
77
|
|
|
} |