Skip to content

Commit

Permalink
Fixed the debug command for Symfony 2.4+
Browse files Browse the repository at this point in the history
This backports the fixes done by @ClementGautier in the 2.0 version of
the bundle.
Closes #127
  • Loading branch information
stof committed Jan 23, 2014
1 parent 04be8d9 commit dade3bb
Showing 1 changed file with 34 additions and 3 deletions.
37 changes: 34 additions & 3 deletions Command/RouterDebugExposedCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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'),
));
}
}
}
}

1 comment on commit dade3bb

@willdurand
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

cool!

Please sign in to comment.