Final Class Yiisoft\Router\Debug\DebugRoutesCommand
| Inheritance | Yiisoft\Router\Debug\DebugRoutesCommand » Symfony\Component\Console\Command\Command |
|---|
Public Methods
| Method | Description | Defined By |
|---|---|---|
| __construct() | Yiisoft\Router\Debug\DebugRoutesCommand |
Protected Methods
| Method | Description | Defined By |
|---|---|---|
| configure() | Yiisoft\Router\Debug\DebugRoutesCommand | |
| execute() | Yiisoft\Router\Debug\DebugRoutesCommand | |
| export() | Yiisoft\Router\Debug\DebugRoutesCommand |
Constants
| Constant | Value | Description | Defined By |
|---|---|---|---|
| COMMAND_NAME | 'debug:routes' | Yiisoft\Router\Debug\DebugRoutesCommand |
Method Details
| public mixed __construct ( Yiisoft\Router\RouteCollectionInterface $routeCollection, \Yiisoft\Yii\Debug\Debugger $debugger ) | ||
| $routeCollection | Yiisoft\Router\RouteCollectionInterface | |
| $debugger | \Yiisoft\Yii\Debug\Debugger | |
public function __construct(
private readonly RouteCollectionInterface $routeCollection,
private readonly Debugger $debugger,
) {
parent::__construct();
}
| protected void configure ( ) |
protected function configure(): void
{
$this->addArgument('route', InputArgument::IS_ARRAY, 'Route name');
}
| protected integer execute ( \Symfony\Component\Console\Input\InputInterface $input, \Symfony\Component\Console\Output\OutputInterface $output ) | ||
| $input | \Symfony\Component\Console\Input\InputInterface | |
| $output | \Symfony\Component\Console\Output\OutputInterface | |
protected function execute(InputInterface $input, OutputInterface $output): int
{
$this->debugger->stop();
$io = new SymfonyStyle($input, $output);
if ($input->hasArgument('route') && !empty($input->getArgument('route'))) {
/**
* @var string[] $routes
*/
$routes = (array) $input->getArgument('route');
foreach ($routes as $route) {
$route = $this->routeCollection->getRoute($route);
$data = $route->__debugInfo();
$action = '';
$middlewares = [];
if (!empty($data['enabledMiddlewares'])) {
$middlewareDefinitions = $data['enabledMiddlewares'];
$action = array_pop($middlewareDefinitions);
$middlewares = $middlewareDefinitions;
}
$io->title($data['name']);
$definitionList = [
['Methods' => $this->export($data['methods'])],
['Name' => $data['name']],
['Pattern' => $data['pattern']],
];
if (!empty($action)) {
$definitionList[] = ['Action' => $this->export($action)];
}
if (!empty($data['defaults'])) {
$definitionList[] = ['Defaults' => $this->export($data['defaults'])];
}
if (!empty($data['hosts'])) {
$definitionList[] = ['Hosts' => $this->export($data['hosts'])];
}
$io->definitionList(...$definitionList);
if (!empty($middlewares)) {
$io->section('Middlewares');
foreach ($middlewares as $middleware) {
$io->writeln(is_string($middleware) ? $middleware : $this->export($middleware));
}
}
}
return 0;
}
$table = new Table($output);
$rows = [];
foreach ($this->routeCollection->getRoutes() as $route) {
$data = $route->__debugInfo();
$action = '';
if (!empty($data['enabledMiddlewares'])) {
$middlewareDefinitions = $data['enabledMiddlewares'];
$action = array_pop($middlewareDefinitions);
}
$rows[] = [
'methods' => $this->export($data['methods']),
'name' => $data['name'],
'hosts' => $this->export($data['hosts']),
'pattern' => $data['pattern'],
'defaults' => $this->export($data['defaults']),
'action' => $this->export($action),
];
}
$table->addRows($rows);
$table->render();
return 0;
}
| protected string export ( mixed $value ) | ||
| $value | mixed | |
protected function export(mixed $value): string
{
if (is_array($value)
&& count($value) === 2
&& isset($value[0], $value[1])
&& is_string($value[0])
&& is_string($value[1])
) {
return $value[0] . '::' . $value[1];
}
if (is_array($value) && $this->isArrayList($value)) {
return implode(', ', array_map($this->export(...), $value));
}
if (is_string($value)) {
return $value;
}
return VarDumper::create($value)->asString();
}
Signup or Login in order to comment.