diff --git a/src/Symfony/Bundle/FrameworkBundle/Command/RouterApacheDumperCommand.php b/src/Symfony/Bundle/FrameworkBundle/Command/RouterApacheDumperCommand.php index bfbfaa78bc48..f092b118d29f 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Command/RouterApacheDumperCommand.php +++ b/src/Symfony/Bundle/FrameworkBundle/Command/RouterApacheDumperCommand.php @@ -15,6 +15,7 @@ use Symfony\Component\Console\Input\InputOption; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Output\OutputInterface; +use Symfony\Component\Console\Style\SymfonyStyle; use Symfony\Component\Routing\Matcher\Dumper\ApacheMatcherDumper; use Symfony\Component\Routing\RouterInterface; @@ -74,9 +75,11 @@ protected function configure() */ protected function execute(InputInterface $input, OutputInterface $output) { - $formatter = $this->getHelper('formatter'); + $output = new SymfonyStyle($input, $output); - $output->writeln($formatter->formatSection('warning', 'The router:dump-apache command is deprecated since version 2.5 and will be removed in 3.0', 'comment')); + $output->title('Router Apache Dumper'); + + $output->caution('The router:dump-apache command is deprecated since version 2.5 and will be removed in 3.0.'); $router = $this->getContainer()->get('router'); diff --git a/src/Symfony/Bundle/FrameworkBundle/Command/RouterDebugCommand.php b/src/Symfony/Bundle/FrameworkBundle/Command/RouterDebugCommand.php index dc5558c06348..80d944b45aa9 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Command/RouterDebugCommand.php +++ b/src/Symfony/Bundle/FrameworkBundle/Command/RouterDebugCommand.php @@ -16,6 +16,7 @@ use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Input\InputOption; use Symfony\Component\Console\Output\OutputInterface; +use Symfony\Component\Console\Style\SymfonyStyle; use Symfony\Component\Routing\RouterInterface; use Symfony\Component\Routing\Route; @@ -77,8 +78,10 @@ protected function configure() */ protected function execute(InputInterface $input, OutputInterface $output) { + $output = new SymfonyStyle($input, $output); + if (false !== strpos($input->getFirstArgument(), ':d')) { - $output->writeln('The use of "router:debug" command is deprecated since version 2.7 and will be removed in 3.0. Use the "debug:router" instead.'); + $output->caution('The use of "router:debug" command is deprecated since version 2.7 and will be removed in 3.0. Use the "debug:router" instead.'); } $name = $input->getArgument('name'); @@ -89,11 +92,14 @@ protected function execute(InputInterface $input, OutputInterface $output) if (!$route) { throw new \InvalidArgumentException(sprintf('The route "%s" does not exist.', $name)); } + $this->convertController($route); + $helper->describe($output, $route, array( 'format' => $input->getOption('format'), 'raw_text' => $input->getOption('raw'), 'name' => $name, + 'output' => $output, )); } else { $routes = $this->getContainer()->get('router')->getRouteCollection(); @@ -106,6 +112,7 @@ protected function execute(InputInterface $input, OutputInterface $output) 'format' => $input->getOption('format'), 'raw_text' => $input->getOption('raw'), 'show_controllers' => $input->getOption('show-controllers'), + 'output' => $output, )); } } diff --git a/src/Symfony/Bundle/FrameworkBundle/Command/RouterMatchCommand.php b/src/Symfony/Bundle/FrameworkBundle/Command/RouterMatchCommand.php index c1afc9d83b7e..ee690770037e 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Command/RouterMatchCommand.php +++ b/src/Symfony/Bundle/FrameworkBundle/Command/RouterMatchCommand.php @@ -11,11 +11,12 @@ namespace Symfony\Bundle\FrameworkBundle\Command; +use Symfony\Component\Console\Input\ArrayInput; use Symfony\Component\Console\Input\InputArgument; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Input\InputOption; use Symfony\Component\Console\Output\OutputInterface; -use Symfony\Component\Console\Input\ArrayInput; +use Symfony\Component\Console\Style\SymfonyStyle; use Symfony\Component\Routing\RouterInterface; use Symfony\Component\Routing\Matcher\TraceableUrlMatcher; @@ -60,7 +61,7 @@ protected function configure() The %command.name% shows which routes match a given request and which don't and for what reason: php %command.full_name% /foo - + or php %command.full_name% /foo --method POST --scheme https --host symfony.com --verbose @@ -75,6 +76,8 @@ protected function configure() */ protected function execute(InputInterface $input, OutputInterface $output) { + $output = new SymfonyStyle($input, $output); + $router = $this->getContainer()->get('router'); $context = $router->getContext(); if (null !== $method = $input->getOption('method')) { @@ -91,25 +94,26 @@ protected function execute(InputInterface $input, OutputInterface $output) $traces = $matcher->getTraces($input->getArgument('path_info')); + $output->newLine(); + $matches = false; foreach ($traces as $trace) { if (TraceableUrlMatcher::ROUTE_ALMOST_MATCHES == $trace['level']) { - $output->writeln(sprintf('Route "%s" almost matches but %s', $trace['name'], lcfirst($trace['log']))); + $output->text(sprintf('Route "%s" almost matches but %s', $trace['name'], lcfirst($trace['log']))); } elseif (TraceableUrlMatcher::ROUTE_MATCHES == $trace['level']) { - $output->writeln(sprintf('Route "%s" matches', $trace['name'])); + $output->success(sprintf('Route "%s" matches', $trace['name'])); - $routerDebugcommand = $this->getApplication()->find('debug:router'); - $output->writeln(''); - $routerDebugcommand->run(new ArrayInput(array('name' => $trace['name'])), $output); + $routerDebugCommand = $this->getApplication()->find('debug:router'); + $routerDebugCommand->run(new ArrayInput(array('name' => $trace['name'])), $output); $matches = true; } elseif ($input->getOption('verbose')) { - $output->writeln(sprintf('Route "%s" does not match: %s', $trace['name'], $trace['log'])); + $output->text(sprintf('Route "%s" does not match: %s', $trace['name'], $trace['log'])); } } if (!$matches) { - $output->writeln(sprintf('None of the routes match the path "%s"', $input->getArgument('path_info'))); + $output->error(sprintf('None of the routes match the path "%s"', $input->getArgument('path_info'))); return 1; } diff --git a/src/Symfony/Bundle/FrameworkBundle/Console/Descriptor/TextDescriptor.php b/src/Symfony/Bundle/FrameworkBundle/Console/Descriptor/TextDescriptor.php index 56ffa455faca..03158d3d0d17 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Console/Descriptor/TextDescriptor.php +++ b/src/Symfony/Bundle/FrameworkBundle/Console/Descriptor/TextDescriptor.php @@ -34,11 +34,13 @@ class TextDescriptor extends Descriptor protected function describeRouteCollection(RouteCollection $routes, array $options = array()) { $showControllers = isset($options['show_controllers']) && $options['show_controllers']; - $headers = array('Name', 'Method', 'Scheme', 'Host', 'Path'); - $table = new Table($this->getOutput()); - $table->setStyle('compact'); - $table->setHeaders($showControllers ? array_merge($headers, array('Controller')) : $headers); + $tableHeaders = array('Name', 'Method', 'Scheme', 'Host', 'Path'); + if ($showControllers) { + $tableHeaders[] = 'Controller'; + } + + $tableRows = array(); foreach ($routes->all() as $name => $route) { $row = array( $name, @@ -58,11 +60,16 @@ protected function describeRouteCollection(RouteCollection $routes, array $optio $row[] = $controller; } - $table->addRow($row); + $tableRows[] = $row; } - $this->writeText($this->formatSection('router', 'Current routes')."\n", $options); - $table->render(); + if (isset($options['output'])) { + $options['output']->table($tableHeaders, $tableRows); + } else { + $table = new Table($this->getOutput()); + $table->setHeaders($tableHeaders)->setRows($tableRows); + $table->render(); + } } /** @@ -73,26 +80,24 @@ protected function describeRoute(Route $route, array $options = array()) $requirements = $route->getRequirements(); unset($requirements['_scheme'], $requirements['_method']); - // fixme: values were originally written as raw - $description = array( - 'Path '.$route->getPath(), - 'Path Regex '.$route->compile()->getRegex(), - 'Host '.('' !== $route->getHost() ? $route->getHost() : 'ANY'), - 'Host Regex '.('' !== $route->getHost() ? $route->compile()->getHostRegex() : ''), - 'Scheme '.($route->getSchemes() ? implode('|', $route->getSchemes()) : 'ANY'), - 'Method '.($route->getMethods() ? implode('|', $route->getMethods()) : 'ANY'), - 'Class '.get_class($route), - 'Defaults '.$this->formatRouterConfig($route->getDefaults()), - 'Requirements '.($requirements ? $this->formatRouterConfig($requirements) : 'NO CUSTOM'), - 'Options '.$this->formatRouterConfig($route->getOptions()), + $tableHeaders = array('Property', 'Value'); + $tableRows = array( + array('Route Name', $options['name']), + array('Path', $route->getPath()), + array('Path Regex', $route->compile()->getRegex()), + array('Host', ('' !== $route->getHost() ? $route->getHost() : 'ANY')), + array('Host Regex', ('' !== $route->getHost() ? $route->compile()->getHostRegex() : '')), + array('Scheme', ($route->getSchemes() ? implode('|', $route->getSchemes()) : 'ANY')), + array('Method', ($route->getMethods() ? implode('|', $route->getMethods()) : 'ANY')), + array('Requirements', ($requirements ? $this->formatRouterConfig($requirements) : 'NO CUSTOM')), + array('Class', get_class($route)), + array('Defaults', $this->formatRouterConfig($route->getDefaults())), + array('Options', $this->formatRouterConfig($route->getOptions())), ); - if (isset($options['name'])) { - array_unshift($description, 'Name '.$options['name']); - array_unshift($description, $this->formatSection('router', sprintf('Route "%s"', $options['name']))); - } - - $this->writeText(implode("\n", $description)."\n", $options); + $table = new Table($this->getOutput()); + $table->setHeaders($tableHeaders)->setRows($tableRows); + $table->render(); } /** @@ -174,7 +179,7 @@ protected function describeContainerServices(ContainerBuilder $builder, array $o $serviceIds = isset($options['tag']) && $options['tag'] ? array_keys($builder->findTaggedServiceIds($options['tag'])) : $builder->getServiceIds(); $maxTags = array(); - foreach ($serviceIds as $key => $serviceId) { + foreach ($serviceIds as $key => $serviceId) { $definition = $this->resolveServiceDefinition($builder, $serviceId); if ($definition instanceof Definition) { // filter out private services unless shown explicitly @@ -212,7 +217,7 @@ protected function describeContainerServices(ContainerBuilder $builder, array $o foreach ($definition->getTag($showTag) as $key => $tag) { $tagValues = array(); foreach ($tagsNames as $tagName) { - $tagValues[] = isset($tag[$tagName]) ? $tag[$tagName] : ""; + $tagValues[] = isset($tag[$tagName]) ? $tag[$tagName] : ''; } if (0 === $key) { $table->addRow(array_merge(array($serviceId), $tagValues, array($definition->getClass()))); @@ -225,10 +230,10 @@ protected function describeContainerServices(ContainerBuilder $builder, array $o } } elseif ($definition instanceof Alias) { $alias = $definition; - $table->addRow(array_merge(array($serviceId, sprintf('alias for "%s"', $alias)), $tagsCount ? array_fill(0, $tagsCount, "") : array())); + $table->addRow(array_merge(array($serviceId, sprintf('alias for "%s"', $alias)), $tagsCount ? array_fill(0, $tagsCount, '') : array())); } else { // we have no information (happens with "service_container") - $table->addRow(array_merge(array($serviceId, get_class($definition)), $tagsCount ? array_fill(0, $tagsCount, "") : array())); + $table->addRow(array_merge(array($serviceId, get_class($definition)), $tagsCount ? array_fill(0, $tagsCount, '') : array())); } } @@ -245,7 +250,7 @@ protected function describeContainerDefinition(Definition $definition, array $op : array(); $description[] = sprintf('Service Id %s', isset($options['id']) ? $options['id'] : '-'); - $description[] = sprintf('Class %s', $definition->getClass() ?: "-"); + $description[] = sprintf('Class %s', $definition->getClass() ?: '-'); $tags = $definition->getTags(); if (count($tags)) { @@ -376,23 +381,24 @@ protected function describeCallable($callable, array $options = array()) } /** - * @param array $array + * @param array $config * * @return string */ - private function formatRouterConfig(array $array) + private function formatRouterConfig(array $config) { - if (!count($array)) { + if (empty($config)) { return 'NONE'; } - $string = ''; - ksort($array); - foreach ($array as $name => $value) { - $string .= ($string ? "\n".str_repeat(' ', 13) : '').$name.': '.$this->formatValue($value); + ksort($config); + + $configAsString = ''; + foreach ($config as $key => $value) { + $configAsString .= sprintf("\n%s: %s", $key, $this->formatValue($value)); } - return $string; + return trim($configAsString); } /** pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy