* * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace Symfony\Bundle\FrameworkBundle\Command; use Symfony\Bundle\FrameworkBundle\Console\Helper\DescriptorHelper; 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\Routing\RouterInterface; /** * A console command for retrieving information about routes * * @author Fabien Potencier * @author Tobias Schultze */ class RouterDebugCommand extends ContainerAwareCommand { /** * {@inheritdoc} */ public function isEnabled() { if (!$this->getContainer()->has('router')) { return false; } $router = $this->getContainer()->get('router'); if (!$router instanceof RouterInterface) { return false; } return parent::isEnabled(); } /** * {@inheritdoc} */ protected function configure() { $this ->setName('router:debug') ->setDefinition(array( new InputArgument('name', InputArgument::OPTIONAL, 'A route name'), new InputOption('show-controllers', null, InputOption::VALUE_NONE, 'Show assigned controllers in overview'), new InputOption('format', null, InputOption::VALUE_REQUIRED, 'To output route(s) in other formats'), new InputOption('raw', null, InputOption::VALUE_NONE, 'To output raw route(s)'), )) ->setDescription('Displays current routes for an application') ->setHelp(<<%command.name% displays the configured routes: php %command.full_name% EOF ) ; } /** * {@inheritdoc} * * @throws \InvalidArgumentException When route does not exist */ protected function execute(InputInterface $input, OutputInterface $output) { $name = $input->getArgument('name'); $helper = new DescriptorHelper(); if ($name) { $route = $this->getContainer()->get('router')->getRouteCollection()->get($name); if (!$route) { throw new \InvalidArgumentException(sprintf('The route "%s" does not exist.', $name)); } $helper->describe($output, $route, $input->getOption('format'), $input->getOption('raw'), array('name' => $name)); } else { $routes = $this->getContainer()->get('router')->getRouteCollection(); $helper->describe($output, $routes, array( 'format' => $input->getOption('format'), 'raw_text' => $input->getOption('raw'), 'show_controllers' => $input->getOption('show-controllers'), )); } } }