routeProvider = $routeProvider; parent::__construct(); } protected function configure() { $this ->setName('debug:router') ->setDescription($this->trans('commands.debug.router.description')) ->addArgument( 'route-name', InputArgument::OPTIONAL | InputArgument::IS_ARRAY, $this->trans('commands.debug.router.arguments.route-name') ) ->setAliases(['dr']); } protected function execute(InputInterface $input, OutputInterface $output) { $route_name = $input->getArgument('route-name'); if ($route_name) { $this->getRouteByNames($route_name); } else { $this->getAllRoutes(); } } protected function getAllRoutes() { $routes = $this->routeProvider->getAllRoutes(); $tableHeader = [ $this->trans('commands.debug.router.messages.name'), $this->trans('commands.debug.router.messages.path'), ]; $tableRows = []; foreach ($routes as $route_name => $route) { $tableRows[] = [$route_name, $route->getPath()]; } $this->getIo()->table($tableHeader, $tableRows, 'compact'); } protected function getRouteByNames($route_name) { $routes = $this->routeProvider->getRoutesByNames($route_name); foreach ($routes as $name => $route) { $tableHeader = [ $this->trans('commands.debug.router.messages.route'), ''.$name.'' ]; $tableRows = []; $tableRows[] = [ ''.$this->trans('commands.debug.router.messages.path').'', $route->getPath(), ]; $tableRows[] = [''.$this->trans('commands.debug.router.messages.defaults').'']; $attributes = $this->addRouteAttributes($route->getDefaults()); foreach ($attributes as $attribute) { $tableRows[] = $attribute; } $tableRows[] = [''.$this->trans('commands.debug.router.messages.requirements').'']; $requirements = $this->addRouteAttributes($route->getRequirements()); foreach ($requirements as $requirement) { $tableRows[] = $requirement; } $tableRows[] = [''.$this->trans('commands.debug.router.messages.options').'']; $options = $this->addRouteAttributes($route->getOptions()); foreach ($options as $option) { $tableRows[] = $option; } $this->getIo()->table($tableHeader, $tableRows, 'compact'); } } protected function addRouteAttributes($attr, $attributes = null) { foreach ($attr as $key => $value) { if (is_array($value)) { $attributes[] = [ ' '.$key, str_replace( '- ', '', Yaml::encode($value) ) ]; } else { $attributes[] = [' '.$key, $value]; } } return $attributes; } }