X-Git-Url: http://www.aleph1.co.uk/gitweb/?p=yaffs-website;a=blobdiff_plain;f=vendor%2Fdrupal%2Fconsole%2Fsrc%2FCommand%2FRouter%2FDebugCommand.php;fp=vendor%2Fdrupal%2Fconsole%2Fsrc%2FCommand%2FRouter%2FDebugCommand.php;h=0c0f902f446d1b58ab56ff6ef1a960c3f16c31df;hp=0000000000000000000000000000000000000000;hb=a2bd1bf0c2c1f1a17d188f4dc0726a45494cefae;hpb=57c063afa3f66b07c4bbddc2d6129a96d90f0aad diff --git a/vendor/drupal/console/src/Command/Router/DebugCommand.php b/vendor/drupal/console/src/Command/Router/DebugCommand.php new file mode 100644 index 000000000..0c0f902f4 --- /dev/null +++ b/vendor/drupal/console/src/Command/Router/DebugCommand.php @@ -0,0 +1,138 @@ +routeProvider = $routeProvider; + parent::__construct(); + } + + protected function configure() + { + $this + ->setName('router:debug') + ->setDescription($this->trans('commands.router.debug.description')) + ->addArgument( + 'route-name', + InputArgument::OPTIONAL | InputArgument::IS_ARRAY, + $this->trans('commands.router.debug.arguments.route-name') + ); + } + + protected function execute(InputInterface $input, OutputInterface $output) + { + $io = new DrupalStyle($input, $output); + + $route_name = $input->getArgument('route-name'); + + if ($route_name) { + $this->getRouteByNames($io, $route_name); + } else { + $this->getAllRoutes($io); + } + } + + protected function getAllRoutes(DrupalStyle $io) + { + $routes = $this->routeProvider->getAllRoutes(); + + $tableHeader = [ + $this->trans('commands.router.debug.messages.name'), + $this->trans('commands.router.debug.messages.path'), + ]; + + $tableRows = []; + foreach ($routes as $route_name => $route) { + $tableRows[] = [$route_name, $route->getPath()]; + } + + $io->table($tableHeader, $tableRows, 'compact'); + } + + protected function getRouteByNames(DrupalStyle $io, $route_name) + { + $routes = $this->routeProvider->getRoutesByNames($route_name); + + foreach ($routes as $name => $route) { + $tableHeader = [ + $this->trans('commands.router.debug.messages.route'), + ''.$name.'' + ]; + $tableRows = []; + + $tableRows[] = [ + ''.$this->trans('commands.router.debug.messages.path').'', + $route->getPath(), + ]; + + $tableRows[] = [''.$this->trans('commands.router.debug.messages.defaults').'']; + $attributes = $this->addRouteAttributes($route->getDefaults()); + foreach ($attributes as $attribute) { + $tableRows[] = $attribute; + } + + $tableRows[] = [''.$this->trans('commands.router.debug.messages.requirements').'']; + $requirements = $this->addRouteAttributes($route->getRequirements()); + foreach ($requirements as $requirement) { + $tableRows[] = $requirement; + } + + $tableRows[] = [''.$this->trans('commands.router.debug.messages.options').'']; + $options = $this->addRouteAttributes($route->getOptions()); + foreach ($options as $option) { + $tableRows[] = $option; + } + + $io->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; + } +}