0 follower

Final Class Yiisoft\Router\Debug\DebugRoutesCommand

InheritanceYiisoft\Router\Debug\DebugRoutesCommand » Symfony\Component\Console\Command\Command

Constants

Hide inherited constants

Constant Value Description Defined By
COMMAND_NAME 'debug:routes' Yiisoft\Router\Debug\DebugRoutesCommand

Method Details

Hide inherited methods

__construct() public method

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();
}

            
configure() protected method

protected void configure ( )

                protected function configure(): void
{
    $this->addArgument('route', InputArgument::IS_ARRAY, 'Route name');
}

            
execute() protected method

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;
}

            
export() protected method

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();
}