|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
namespace Yiisoft\Yii\Debug\Command; |
|
6
|
|
|
|
|
7
|
|
|
use Symfony\Component\Console\Command\Command; |
|
8
|
|
|
use Symfony\Component\Console\Helper\Table; |
|
9
|
|
|
use Symfony\Component\Console\Input\InputArgument; |
|
10
|
|
|
use Symfony\Component\Console\Input\InputInterface; |
|
11
|
|
|
use Symfony\Component\Console\Output\OutputInterface; |
|
12
|
|
|
use Symfony\Component\Console\Style\SymfonyStyle; |
|
13
|
|
|
use Yiisoft\Router\RouteCollectionInterface; |
|
|
|
|
|
|
14
|
|
|
use Yiisoft\VarDumper\VarDumper; |
|
15
|
|
|
use Yiisoft\Yii\Console\ExitCode; |
|
16
|
|
|
use Yiisoft\Yii\Debug\Debugger; |
|
17
|
|
|
|
|
18
|
|
|
final class DebugRoutesCommand extends Command |
|
19
|
|
|
{ |
|
20
|
|
|
public const COMMAND_NAME = 'debug:routes'; |
|
21
|
|
|
protected static $defaultName = self::COMMAND_NAME; |
|
22
|
|
|
|
|
23
|
|
|
public function __construct( |
|
24
|
|
|
private RouteCollectionInterface $routeCollection, |
|
25
|
|
|
private Debugger $debugger, |
|
26
|
|
|
) { |
|
27
|
|
|
parent::__construct(); |
|
28
|
|
|
} |
|
29
|
|
|
|
|
30
|
|
|
protected function configure(): void |
|
31
|
|
|
{ |
|
32
|
|
|
$this |
|
33
|
|
|
->setDescription('Show information about registered routes') |
|
34
|
|
|
->addArgument('route', InputArgument::IS_ARRAY, 'Route name'); |
|
35
|
|
|
} |
|
36
|
|
|
|
|
37
|
|
|
protected function execute(InputInterface $input, OutputInterface $output): int |
|
38
|
|
|
{ |
|
39
|
|
|
$this->debugger->stop(); |
|
40
|
|
|
|
|
41
|
|
|
$io = new SymfonyStyle($input, $output); |
|
42
|
|
|
|
|
43
|
|
|
if ($input->hasArgument('route') && !empty($input->getArgument('route'))) { |
|
44
|
|
|
$routes = (array) $input->getArgument('route'); |
|
45
|
|
|
foreach ($routes as $route) { |
|
46
|
|
|
$route = $this->routeCollection->getRoute($route); |
|
47
|
|
|
$data = $route->__debugInfo(); |
|
48
|
|
|
$action = ''; |
|
49
|
|
|
$middlewares = []; |
|
50
|
|
|
if (!empty($data['middlewareDefinitions'])) { |
|
51
|
|
|
$middlewareDefinitions = $data['middlewareDefinitions']; |
|
52
|
|
|
$action = array_pop($middlewareDefinitions); |
|
53
|
|
|
$middlewares = $middlewareDefinitions; |
|
54
|
|
|
} |
|
55
|
|
|
|
|
56
|
|
|
$io->title($data['name']); |
|
57
|
|
|
$definitionList = [ |
|
58
|
|
|
['Methods' => $this->export($data['methods'])], |
|
59
|
|
|
['Name' => $data['name']], |
|
60
|
|
|
['Pattern' => $data['pattern']], |
|
61
|
|
|
]; |
|
62
|
|
|
if (!empty($action)) { |
|
63
|
|
|
$definitionList[] = ['Action' => $this->export($action)]; |
|
64
|
|
|
} |
|
65
|
|
|
if (!empty($data['defaults'])) { |
|
66
|
|
|
$definitionList[] = ['Defaults' => $this->export($data['defaults'])]; |
|
67
|
|
|
} |
|
68
|
|
|
if (!empty($data['hosts'])) { |
|
69
|
|
|
$definitionList[] = ['Hosts' => $this->export($data['hosts'])]; |
|
70
|
|
|
} |
|
71
|
|
|
|
|
72
|
|
|
$io->definitionList(...$definitionList); |
|
73
|
|
|
if (!empty($middlewares)) { |
|
74
|
|
|
$io->section('Middlewares'); |
|
75
|
|
|
foreach ($middlewares as $middleware) { |
|
76
|
|
|
$io->writeln(is_string($middleware) ? $middleware : $this->export($middleware)); |
|
77
|
|
|
} |
|
78
|
|
|
} |
|
79
|
|
|
} |
|
80
|
|
|
|
|
81
|
|
|
return ExitCode::OK; |
|
82
|
|
|
} |
|
83
|
|
|
|
|
84
|
|
|
$table = new Table($output); |
|
85
|
|
|
$rows = []; |
|
86
|
|
|
foreach ($this->routeCollection->getRoutes() as $route) { |
|
87
|
|
|
$data = $route->__debugInfo(); |
|
88
|
|
|
$action = ''; |
|
89
|
|
|
if (!empty($data['middlewareDefinitions'])) { |
|
90
|
|
|
$middlewareDefinitions = $data['middlewareDefinitions']; |
|
91
|
|
|
$action = array_pop($middlewareDefinitions); |
|
92
|
|
|
} |
|
93
|
|
|
$rows[] = [ |
|
94
|
|
|
'methods' => $this->export($data['methods']), |
|
95
|
|
|
'name' => $data['name'], |
|
96
|
|
|
'hosts' => $this->export($data['hosts']), |
|
97
|
|
|
'pattern' => $data['pattern'], |
|
98
|
|
|
'defaults' => $this->export($data['defaults']), |
|
99
|
|
|
'action' => $this->export($action), |
|
100
|
|
|
]; |
|
101
|
|
|
} |
|
102
|
|
|
$table->addRows($rows); |
|
103
|
|
|
$table->render(); |
|
104
|
|
|
|
|
105
|
|
|
return ExitCode::OK; |
|
106
|
|
|
} |
|
107
|
|
|
|
|
108
|
|
|
protected function export(mixed $value): string |
|
109
|
|
|
{ |
|
110
|
|
|
if (is_array($value) |
|
|
|
|
|
|
111
|
|
|
&& count($value) === 2 |
|
112
|
|
|
&& isset($value[0], $value[1]) |
|
113
|
|
|
&& is_string($value[0]) |
|
114
|
|
|
&& is_string($value[1]) |
|
115
|
|
|
) { |
|
116
|
|
|
return $value[0] . '::' . $value[1]; |
|
117
|
|
|
} |
|
118
|
|
|
if (is_array($value) && array_is_list($value)) { |
|
|
|
|
|
|
119
|
|
|
return implode(', ', array_map(fn ($item) => $this->export($item), $value)); |
|
120
|
|
|
} |
|
121
|
|
|
if (is_string($value)) { |
|
122
|
|
|
return $value; |
|
123
|
|
|
} |
|
124
|
|
|
return VarDumper::create($value)->asString(); |
|
125
|
|
|
} |
|
126
|
|
|
} |
|
127
|
|
|
|
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths