From dade3bb0b21007e5c0fb40f203ed197841eb913c Mon Sep 17 00:00:00 2001 From: Christophe Coevoet Date: Thu, 23 Jan 2014 22:25:39 +0100 Subject: [PATCH] Fixed the debug command for Symfony 2.4+ This backports the fixes done by @ClementGautier in the 2.0 version of the bundle. Closes #127 --- Command/RouterDebugExposedCommand.php | 37 ++++++++++++++++++++++++--- 1 file changed, 34 insertions(+), 3 deletions(-) diff --git a/Command/RouterDebugExposedCommand.php b/Command/RouterDebugExposedCommand.php index 8ca017da..c770507f 100644 --- a/Command/RouterDebugExposedCommand.php +++ b/Command/RouterDebugExposedCommand.php @@ -11,9 +11,12 @@ namespace FOS\JsRoutingBundle\Command; +use FOS\JsRoutingBundle\Extractor\ExposedRoutesExtractorInterface; use Symfony\Bundle\FrameworkBundle\Command\RouterDebugCommand; +use Symfony\Bundle\FrameworkBundle\Console\Helper\DescriptorHelper; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Output\OutputInterface; +use Symfony\Component\Routing\RouteCollection; /** * A console command for retrieving information about exposed routes. @@ -51,20 +54,48 @@ protected function configure() */ protected function execute(InputInterface $input, OutputInterface $output) { + /** @var ExposedRoutesExtractorInterface $extractor */ $extractor = $this->getContainer()->get('fos_js_routing.extractor'); if ($input->getArgument('name')) { $route = $this->getContainer()->get('router')->getRouteCollection()->get($input->getArgument('name')); + if (!$route) { throw new \InvalidArgumentException(sprintf('The route "%s" does not exist.', $input->getArgument('name'))); } + $exposedRoutes = $extractor->getExposedRoutes(); - if (isset($exposedRoutes[$input->getArgument('name')])) { + if (!isset($exposedRoutes[$input->getArgument('name')])) { + throw new \InvalidArgumentException(sprintf('The route "%s" was found, but it is not an exposed route.', $input->getArgument('name'))); + } + + if (!class_exists('Symfony\Bundle\FrameworkBundle\Console\Helper\DescriptorHelper')) { + // BC layer for Symfony 2.3 and lower $this->outputRoute($output, $input->getArgument('name')); } else { - throw new \InvalidArgumentException(sprintf('The route "%s" was found, but it is not an exposed route.', $input->getArgument('name'))); + $helper = new DescriptorHelper(); + $helper->describe($output, $route, array( + 'format' => $input->getOption('format'), + 'raw_text' => $input->getOption('raw'), + 'show_controllers' => $input->getOption('show-controllers'), + )); } } else { - $this->outputRoutes($output, $extractor->getExposedRoutes()); + if (!class_exists('Symfony\Bundle\FrameworkBundle\Console\Helper\DescriptorHelper')) { + // BC layer for Symfony 2.3 and lower + $this->outputRoutes($output, $extractor->getExposedRoutes()); + } else { + $routeCollection = new RouteCollection(); + foreach ($extractor->getExposedRoutes() as $name => $route) { + $routeCollection->add($name, $route); + } + + $helper = new DescriptorHelper(); + $helper->describe($output, $routeCollection, array( + 'format' => $input->getOption('format'), + 'raw_text' => $input->getOption('raw'), + 'show_controllers' => $input->getOption('show-controllers'), + )); + } } } }