5 * Contains \Drupal\Console\Command\Debug\RouterCommand.
8 namespace Drupal\Console\Command\Debug;
10 use Symfony\Component\Console\Input\InputArgument;
11 use Symfony\Component\Console\Input\InputInterface;
12 use Symfony\Component\Console\Output\OutputInterface;
13 use Drupal\Console\Core\Command\Command;
14 use Drupal\Core\Routing\RouteProviderInterface;
15 use Drupal\Component\Serialization\Yaml;
17 class RouterCommand extends Command
20 * @var RouteProviderInterface
22 protected $routeProvider;
25 * DebugCommand constructor.
27 * @param RouteProviderInterface $routeProvider
29 public function __construct(RouteProviderInterface $routeProvider)
31 $this->routeProvider = $routeProvider;
32 parent::__construct();
35 protected function configure()
38 ->setName('debug:router')
39 ->setDescription($this->trans('commands.debug.router.description'))
42 InputArgument::OPTIONAL | InputArgument::IS_ARRAY,
43 $this->trans('commands.debug.router.arguments.route-name')
48 protected function execute(InputInterface $input, OutputInterface $output)
50 $route_name = $input->getArgument('route-name');
53 $this->getRouteByNames($route_name);
55 $this->getAllRoutes();
59 protected function getAllRoutes()
61 $routes = $this->routeProvider->getAllRoutes();
64 $this->trans('commands.debug.router.messages.name'),
65 $this->trans('commands.debug.router.messages.path'),
69 foreach ($routes as $route_name => $route) {
70 $tableRows[] = [$route_name, $route->getPath()];
73 $this->getIo()->table($tableHeader, $tableRows, 'compact');
76 protected function getRouteByNames($route_name)
78 $routes = $this->routeProvider->getRoutesByNames($route_name);
80 foreach ($routes as $name => $route) {
82 $this->trans('commands.debug.router.messages.route'),
83 '<info>'.$name.'</info>'
88 '<comment>'.$this->trans('commands.debug.router.messages.path').'</comment>',
92 $tableRows[] = ['<comment>'.$this->trans('commands.debug.router.messages.defaults').'</comment>'];
93 $attributes = $this->addRouteAttributes($route->getDefaults());
94 foreach ($attributes as $attribute) {
95 $tableRows[] = $attribute;
98 $tableRows[] = ['<comment>'.$this->trans('commands.debug.router.messages.requirements').'</comment>'];
99 $requirements = $this->addRouteAttributes($route->getRequirements());
100 foreach ($requirements as $requirement) {
101 $tableRows[] = $requirement;
104 $tableRows[] = ['<comment>'.$this->trans('commands.debug.router.messages.options').'</comment>'];
105 $options = $this->addRouteAttributes($route->getOptions());
106 foreach ($options as $option) {
107 $tableRows[] = $option;
110 $this->getIo()->table($tableHeader, $tableRows, 'compact');
114 protected function addRouteAttributes($attr, $attributes = null)
116 foreach ($attr as $key => $value) {
117 if (is_array($value)) {
127 $attributes[] = [' '.$key, $value];