From f5f048832a6f5c0711fe08e59d9fc75d55fbd7ea Mon Sep 17 00:00:00 2001 From: Javier Eguiluz Date: Tue, 31 Mar 2015 14:42:44 +0200 Subject: [PATCH 1/8] Applied the new styles to the router: commands --- .../Command/RouterApacheDumperCommand.php | 7 +- .../Command/RouterDebugCommand.php | 119 ++++++++++++++++-- .../Command/RouterMatchCommand.php | 22 ++-- 3 files changed, 126 insertions(+), 22 deletions(-) diff --git a/src/Symfony/Bundle/FrameworkBundle/Command/RouterApacheDumperCommand.php b/src/Symfony/Bundle/FrameworkBundle/Command/RouterApacheDumperCommand.php index bfbfaa78bc48a..f092b118d29f9 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 dc5558c063487..fbb389e0f6e1f 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Command/RouterDebugCommand.php +++ b/src/Symfony/Bundle/FrameworkBundle/Command/RouterDebugCommand.php @@ -16,6 +16,8 @@ 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\RouteCollection; use Symfony\Component\Routing\RouterInterface; use Symfony\Component\Routing\Route; @@ -77,8 +79,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,12 +93,18 @@ 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, - )); + + if ('txt' === $input->getOption('format')) { + $this->displayRouteInformation($name, $route, $output); + } else { + $helper->describe($output, $route, array( + 'format' => $input->getOption('format'), + 'raw_text' => $input->getOption('raw'), + 'name' => $name, + )); + } } else { $routes = $this->getContainer()->get('router')->getRouteCollection(); @@ -102,12 +112,99 @@ protected function execute(InputInterface $input, OutputInterface $output) $this->convertController($route); } - $helper->describe($output, $routes, array( - 'format' => $input->getOption('format'), - 'raw_text' => $input->getOption('raw'), - 'show_controllers' => $input->getOption('show-controllers'), - )); + if ('txt' === $input->getOption('format')) { + $this->displayRouteCollectionInformation($routes, $input->getOption('show-controllers'), $output); + } else { + $helper->describe($output, $routes, array( + 'format' => $input->getOption('format'), + 'raw_text' => $input->getOption('raw'), + 'show_controllers' => $input->getOption('show-controllers'), + )); + } + } + } + + private function displayRouteInformation($name, Route $route, OutputInterface $output) + { + $requirements = $route->getRequirements(); + + $output->table( + array('Property', 'Value'), + array( + array('Route Name', $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())), + ) + ); + } + + private function displayRouteCollectionInformation(RouteCollection $routes, $showControllers, OutputInterface $output) + { + $tableHeaders = array('Name', 'Method', 'Scheme', 'Host', 'Path'); + if ($showControllers) { + $tableHeaders[] = 'Controller'; + } + + $tableRows = array(); + foreach ($routes->all() as $name => $route) { + $row = array( + $name, + $route->getMethods() ? implode('|', $route->getMethods()) : 'ANY', + $route->getSchemes() ? implode('|', $route->getSchemes()) : 'ANY', + '' !== $route->getHost() ? $route->getHost() : 'ANY', + $route->getPath(), + ); + + if ($showControllers) { + $controller = $route->getDefault('_controller'); + if ($controller instanceof \Closure) { + $controller = 'Closure'; + } elseif (is_object($controller)) { + $controller = get_class($controller); + } + $row[] = $controller; + } + + $tableRows[] = $row; + } + + $output->table($tableHeaders, $tableRows); + } + + private function formatRouterConfig(array $config) + { + if (!count($config)) { + return 'NONE'; + } + + $string = ''; + ksort($config); + foreach ($config as $name => $value) { + $string .= sprintf("\n%s: %s", $name, $this->formatValue($value)); } + + return trim($string); + } + + private function formatValue($value) + { + if (is_object($value)) { + return sprintf('object(%s)', get_class($value)); + } + + if (is_string($value)) { + return $value; + } + + return preg_replace("/\n\s*/s", '', var_export($value, true)); } private function convertController(Route $route) diff --git a/src/Symfony/Bundle/FrameworkBundle/Command/RouterMatchCommand.php b/src/Symfony/Bundle/FrameworkBundle/Command/RouterMatchCommand.php index c1afc9d83b7e7..ee690770037e4 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; } From 9ebdcc1326f9aa816a9fd71407b6fcf22368941a Mon Sep 17 00:00:00 2001 From: Javier Eguiluz Date: Wed, 1 Apr 2015 11:19:35 +0200 Subject: [PATCH 2/8] Move the logic to display route information back to the text descriptor --- .../Command/RouterDebugCommand.php | 111 ++---------------- .../Console/Descriptor/TextDescriptor.php | 64 +++++----- 2 files changed, 41 insertions(+), 134 deletions(-) diff --git a/src/Symfony/Bundle/FrameworkBundle/Command/RouterDebugCommand.php b/src/Symfony/Bundle/FrameworkBundle/Command/RouterDebugCommand.php index fbb389e0f6e1f..dc001b140c3dc 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Command/RouterDebugCommand.php +++ b/src/Symfony/Bundle/FrameworkBundle/Command/RouterDebugCommand.php @@ -96,15 +96,11 @@ protected function execute(InputInterface $input, OutputInterface $output) $this->convertController($route); - if ('txt' === $input->getOption('format')) { - $this->displayRouteInformation($name, $route, $output); - } else { - $helper->describe($output, $route, array( - 'format' => $input->getOption('format'), - 'raw_text' => $input->getOption('raw'), - 'name' => $name, - )); - } + $helper->describe($output, $route, array( + 'format' => $input->getOption('format'), + 'raw_text' => $input->getOption('raw'), + 'name' => $name, + )); } else { $routes = $this->getContainer()->get('router')->getRouteCollection(); @@ -112,101 +108,14 @@ protected function execute(InputInterface $input, OutputInterface $output) $this->convertController($route); } - if ('txt' === $input->getOption('format')) { - $this->displayRouteCollectionInformation($routes, $input->getOption('show-controllers'), $output); - } else { - $helper->describe($output, $routes, array( - 'format' => $input->getOption('format'), - 'raw_text' => $input->getOption('raw'), - 'show_controllers' => $input->getOption('show-controllers'), - )); - } + $helper->describe($output, $routes, array( + 'format' => $input->getOption('format'), + 'raw_text' => $input->getOption('raw'), + 'show_controllers' => $input->getOption('show-controllers'), + )); } } - private function displayRouteInformation($name, Route $route, OutputInterface $output) - { - $requirements = $route->getRequirements(); - - $output->table( - array('Property', 'Value'), - array( - array('Route Name', $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())), - ) - ); - } - - private function displayRouteCollectionInformation(RouteCollection $routes, $showControllers, OutputInterface $output) - { - $tableHeaders = array('Name', 'Method', 'Scheme', 'Host', 'Path'); - if ($showControllers) { - $tableHeaders[] = 'Controller'; - } - - $tableRows = array(); - foreach ($routes->all() as $name => $route) { - $row = array( - $name, - $route->getMethods() ? implode('|', $route->getMethods()) : 'ANY', - $route->getSchemes() ? implode('|', $route->getSchemes()) : 'ANY', - '' !== $route->getHost() ? $route->getHost() : 'ANY', - $route->getPath(), - ); - - if ($showControllers) { - $controller = $route->getDefault('_controller'); - if ($controller instanceof \Closure) { - $controller = 'Closure'; - } elseif (is_object($controller)) { - $controller = get_class($controller); - } - $row[] = $controller; - } - - $tableRows[] = $row; - } - - $output->table($tableHeaders, $tableRows); - } - - private function formatRouterConfig(array $config) - { - if (!count($config)) { - return 'NONE'; - } - - $string = ''; - ksort($config); - foreach ($config as $name => $value) { - $string .= sprintf("\n%s: %s", $name, $this->formatValue($value)); - } - - return trim($string); - } - - private function formatValue($value) - { - if (is_object($value)) { - return sprintf('object(%s)', get_class($value)); - } - - if (is_string($value)) { - return $value; - } - - return preg_replace("/\n\s*/s", '', var_export($value, true)); - } - private function convertController(Route $route) { $nameParser = $this->getContainer()->get('controller_name_converter'); diff --git a/src/Symfony/Bundle/FrameworkBundle/Console/Descriptor/TextDescriptor.php b/src/Symfony/Bundle/FrameworkBundle/Console/Descriptor/TextDescriptor.php index 56ffa455faca8..7dc20af5c5bad 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,10 @@ 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(); + $this->getOutput()->table($tableHeaders, $tableRows); } /** @@ -73,26 +74,22 @@ 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); + $this->getOutput()->table($tableHeaders, $tableRows); } /** @@ -376,23 +373,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); } /** From 488a80f12ef1e53df40457af7b548e61cf56e904 Mon Sep 17 00:00:00 2001 From: Javier Eguiluz Date: Wed, 1 Apr 2015 11:42:40 +0200 Subject: [PATCH 3/8] Improve a variable name and fixed the text descriptor code --- .../Bundle/FrameworkBundle/Command/RouterDebugCommand.php | 6 ++++-- .../FrameworkBundle/Console/Descriptor/TextDescriptor.php | 4 ++-- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/src/Symfony/Bundle/FrameworkBundle/Command/RouterDebugCommand.php b/src/Symfony/Bundle/FrameworkBundle/Command/RouterDebugCommand.php index dc001b140c3dc..7dca0404a4e58 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Command/RouterDebugCommand.php +++ b/src/Symfony/Bundle/FrameworkBundle/Command/RouterDebugCommand.php @@ -79,10 +79,10 @@ protected function configure() */ protected function execute(InputInterface $input, OutputInterface $output) { - $output = new SymfonyStyle($input, $output); + $outputHelper = new SymfonyStyle($input, $output); if (false !== strpos($input->getFirstArgument(), ':d')) { - $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.'); + $outputHelper->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'); @@ -100,6 +100,7 @@ protected function execute(InputInterface $input, OutputInterface $output) 'format' => $input->getOption('format'), 'raw_text' => $input->getOption('raw'), 'name' => $name, + 'output_helper' => $outputHelper, )); } else { $routes = $this->getContainer()->get('router')->getRouteCollection(); @@ -112,6 +113,7 @@ protected function execute(InputInterface $input, OutputInterface $output) 'format' => $input->getOption('format'), 'raw_text' => $input->getOption('raw'), 'show_controllers' => $input->getOption('show-controllers'), + 'output_helper' => $outputHelper, )); } } diff --git a/src/Symfony/Bundle/FrameworkBundle/Console/Descriptor/TextDescriptor.php b/src/Symfony/Bundle/FrameworkBundle/Console/Descriptor/TextDescriptor.php index 7dc20af5c5bad..1af870abe752a 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Console/Descriptor/TextDescriptor.php +++ b/src/Symfony/Bundle/FrameworkBundle/Console/Descriptor/TextDescriptor.php @@ -63,7 +63,7 @@ protected function describeRouteCollection(RouteCollection $routes, array $optio $tableRows[] = $row; } - $this->getOutput()->table($tableHeaders, $tableRows); + $options['output_helper']->table($tableHeaders, $tableRows); } /** @@ -89,7 +89,7 @@ protected function describeRoute(Route $route, array $options = array()) array('Options', $this->formatRouterConfig($route->getOptions())), ); - $this->getOutput()->table($tableHeaders, $tableRows); + $options['output_helper']->table($tableHeaders, $tableRows); } /** From f72b69b0417e75f4deeb63a7ecd57c0980e9e4ac Mon Sep 17 00:00:00 2001 From: Javier Eguiluz Date: Wed, 1 Apr 2015 12:04:42 +0200 Subject: [PATCH 4/8] Add a simple logic to pick the best output object available --- .../FrameworkBundle/Console/Descriptor/TextDescriptor.php | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/Symfony/Bundle/FrameworkBundle/Console/Descriptor/TextDescriptor.php b/src/Symfony/Bundle/FrameworkBundle/Console/Descriptor/TextDescriptor.php index 1af870abe752a..4d6bf5467a73b 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Console/Descriptor/TextDescriptor.php +++ b/src/Symfony/Bundle/FrameworkBundle/Console/Descriptor/TextDescriptor.php @@ -63,7 +63,8 @@ protected function describeRouteCollection(RouteCollection $routes, array $optio $tableRows[] = $row; } - $options['output_helper']->table($tableHeaders, $tableRows); + $outputHelper = isset($options['output_helper']) ? $options['output_helper'] : $this->getOutput(); + $outputHelper->table($tableHeaders, $tableRows); } /** @@ -89,7 +90,8 @@ protected function describeRoute(Route $route, array $options = array()) array('Options', $this->formatRouterConfig($route->getOptions())), ); - $options['output_helper']->table($tableHeaders, $tableRows); + $outputHelper = isset($options['output_helper']) ? $options['output_helper'] : $this->getOutput(); + $outputHelper->table($tableHeaders, $tableRows); } /** From e203706d63d1e3c6b0bb80eaa461279470108bca Mon Sep 17 00:00:00 2001 From: Javier Eguiluz Date: Wed, 1 Apr 2015 12:14:54 +0200 Subject: [PATCH 5/8] Removed an unneeded "use" statement --- .../Bundle/FrameworkBundle/Command/RouterDebugCommand.php | 1 - 1 file changed, 1 deletion(-) diff --git a/src/Symfony/Bundle/FrameworkBundle/Command/RouterDebugCommand.php b/src/Symfony/Bundle/FrameworkBundle/Command/RouterDebugCommand.php index 7dca0404a4e58..5bac4e43c2f82 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Command/RouterDebugCommand.php +++ b/src/Symfony/Bundle/FrameworkBundle/Command/RouterDebugCommand.php @@ -17,7 +17,6 @@ use Symfony\Component\Console\Input\InputOption; use Symfony\Component\Console\Output\OutputInterface; use Symfony\Component\Console\Style\SymfonyStyle; -use Symfony\Component\Routing\RouteCollection; use Symfony\Component\Routing\RouterInterface; use Symfony\Component\Routing\Route; From f9de0634b71f73026c267ffffcc284528aba43a9 Mon Sep 17 00:00:00 2001 From: Javier Eguiluz Date: Wed, 1 Apr 2015 13:05:23 +0200 Subject: [PATCH 6/8] Improved the code when the outputHelper is not available --- .../Console/Descriptor/TextDescriptor.php | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/src/Symfony/Bundle/FrameworkBundle/Console/Descriptor/TextDescriptor.php b/src/Symfony/Bundle/FrameworkBundle/Console/Descriptor/TextDescriptor.php index 4d6bf5467a73b..457f0eab6c320 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Console/Descriptor/TextDescriptor.php +++ b/src/Symfony/Bundle/FrameworkBundle/Console/Descriptor/TextDescriptor.php @@ -63,8 +63,13 @@ protected function describeRouteCollection(RouteCollection $routes, array $optio $tableRows[] = $row; } - $outputHelper = isset($options['output_helper']) ? $options['output_helper'] : $this->getOutput(); - $outputHelper->table($tableHeaders, $tableRows); + if (isset($options['output_helper'])) { + $options['output_helper']->table($tableHeaders, $tableRows); + } else { + $table = new Table($this->getOutput()); + $table->setHeaders($tableHeaders)->setRows($tableRows); + $table->render(); + } } /** @@ -90,8 +95,13 @@ protected function describeRoute(Route $route, array $options = array()) array('Options', $this->formatRouterConfig($route->getOptions())), ); - $outputHelper = isset($options['output_helper']) ? $options['output_helper'] : $this->getOutput(); - $outputHelper->table($tableHeaders, $tableRows); + if (isset($options['output_helper'])) { + $options['output_helper']->table($tableHeaders, $tableRows); + } else { + $table = new Table($this->getOutput()); + $table->setHeaders($tableHeaders)->setRows($tableRows); + $table->render(); + } } /** From 90a3e1865ff4a63433453f84a751d1a7e45437aa Mon Sep 17 00:00:00 2001 From: Javier Eguiluz Date: Tue, 7 Apr 2015 17:25:33 +0200 Subject: [PATCH 7/8] Renamed the $outputHelper variable back to just $output --- .../Bundle/FrameworkBundle/Command/RouterDebugCommand.php | 8 ++++---- .../FrameworkBundle/Console/Descriptor/TextDescriptor.php | 4 ++-- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/Symfony/Bundle/FrameworkBundle/Command/RouterDebugCommand.php b/src/Symfony/Bundle/FrameworkBundle/Command/RouterDebugCommand.php index 5bac4e43c2f82..80d944b45aa9f 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Command/RouterDebugCommand.php +++ b/src/Symfony/Bundle/FrameworkBundle/Command/RouterDebugCommand.php @@ -78,10 +78,10 @@ protected function configure() */ protected function execute(InputInterface $input, OutputInterface $output) { - $outputHelper = new SymfonyStyle($input, $output); + $output = new SymfonyStyle($input, $output); if (false !== strpos($input->getFirstArgument(), ':d')) { - $outputHelper->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.'); + $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'); @@ -99,7 +99,7 @@ protected function execute(InputInterface $input, OutputInterface $output) 'format' => $input->getOption('format'), 'raw_text' => $input->getOption('raw'), 'name' => $name, - 'output_helper' => $outputHelper, + 'output' => $output, )); } else { $routes = $this->getContainer()->get('router')->getRouteCollection(); @@ -112,7 +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_helper' => $outputHelper, + 'output' => $output, )); } } diff --git a/src/Symfony/Bundle/FrameworkBundle/Console/Descriptor/TextDescriptor.php b/src/Symfony/Bundle/FrameworkBundle/Console/Descriptor/TextDescriptor.php index 457f0eab6c320..f11c2fdeed4a1 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Console/Descriptor/TextDescriptor.php +++ b/src/Symfony/Bundle/FrameworkBundle/Console/Descriptor/TextDescriptor.php @@ -63,8 +63,8 @@ protected function describeRouteCollection(RouteCollection $routes, array $optio $tableRows[] = $row; } - if (isset($options['output_helper'])) { - $options['output_helper']->table($tableHeaders, $tableRows); + if (isset($options['output'])) { + $options['output']->table($tableHeaders, $tableRows); } else { $table = new Table($this->getOutput()); $table->setHeaders($tableHeaders)->setRows($tableRows); From 83cce3ad836fa0d1099ca1f4d65ed82034ef5fd5 Mon Sep 17 00:00:00 2001 From: Javier Eguiluz Date: Mon, 28 Sep 2015 15:45:04 +0200 Subject: [PATCH 8/8] Removed an unneded variable --- .../Console/Descriptor/TextDescriptor.php | 20 ++++++++----------- 1 file changed, 8 insertions(+), 12 deletions(-) diff --git a/src/Symfony/Bundle/FrameworkBundle/Console/Descriptor/TextDescriptor.php b/src/Symfony/Bundle/FrameworkBundle/Console/Descriptor/TextDescriptor.php index f11c2fdeed4a1..03158d3d0d176 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Console/Descriptor/TextDescriptor.php +++ b/src/Symfony/Bundle/FrameworkBundle/Console/Descriptor/TextDescriptor.php @@ -95,13 +95,9 @@ protected function describeRoute(Route $route, array $options = array()) array('Options', $this->formatRouterConfig($route->getOptions())), ); - if (isset($options['output_helper'])) { - $options['output_helper']->table($tableHeaders, $tableRows); - } else { - $table = new Table($this->getOutput()); - $table->setHeaders($tableHeaders)->setRows($tableRows); - $table->render(); - } + $table = new Table($this->getOutput()); + $table->setHeaders($tableHeaders)->setRows($tableRows); + $table->render(); } /** @@ -183,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 @@ -221,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()))); @@ -234,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())); } } @@ -254,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)) { 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