Вход Регистрация
Файл: symfony-2.7/src/Symfony/Bundle/FrameworkBundle/Command/RouterDebugCommand.php
Строк: 212
<?php

/*
 * This file is part of the Symfony package.
 *
 * (c) Fabien Potencier <fabien@symfony.com>
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */

namespace SymfonyBundleFrameworkBundleCommand;

use 
SymfonyBundleFrameworkBundleConsoleHelperDescriptorHelper;
use 
SymfonyComponentConsoleInputInputArgument;
use 
SymfonyComponentConsoleInputInputInterface;
use 
SymfonyComponentConsoleInputInputOption;
use 
SymfonyComponentConsoleOutputOutputInterface;
use 
SymfonyComponentRoutingRouterInterface;
use 
SymfonyComponentRoutingRoute;

/**
 * A console command for retrieving information about routes.
 *
 * @author Fabien Potencier <fabien@symfony.com>
 * @author Tobias Schultze <http://tobion.de>
 */
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('debug:router')
            ->
setAliases(array(
                
'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'nullInputOption::VALUE_REQUIRED'To output route(s) in other formats''txt'),
                new 
InputOption('raw'nullInputOption::VALUE_NONE'To output raw route(s)'),
            ))
            ->
setDescription('Displays current routes for an application')
            ->
setHelp(<<<EOF
The <info>%command.name%</info> displays the configured routes:

  <info>php %command.full_name%</info>

EOF
            )
        ;
    }

    
/**
     * {@inheritdoc}
     *
     * @throws InvalidArgumentException When route does not exist
     */
    
protected function execute(InputInterface $inputOutputInterface $output)
    {
        if (
false !== strpos($input->getFirstArgument(), ':d')) {
            
$output->writeln('<comment>The use of "router:debug" command is deprecated since version 2.7 and will be removed in 3.0. Use the "debug:router" instead.</comment>');
        }

        
$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));
            }
            
$this->convertController($route);
            
$helper->describe($output$route, array(
                
'format' => $input->getOption('format'),
                
'raw_text' => $input->getOption('raw'),
                
'name' => $name,
            ));
        } else {
            
$routes $this->getContainer()->get('router')->getRouteCollection();

            foreach (
$routes as $route) {
                
$this->convertController($route);
            }

            
$helper->describe($output$routes, array(
                
'format' => $input->getOption('format'),
                
'raw_text' => $input->getOption('raw'),
                
'show_controllers' => $input->getOption('show-controllers'),
            ));
        }
    }

    private function 
convertController(Route $route)
    {
        
$nameParser $this->getContainer()->get('controller_name_converter');
        if (
$route->hasDefault('_controller')) {
            try {
                
$route->setDefault('_controller'$nameParser->build($route->getDefault('_controller')));
            } catch (
InvalidArgumentException $e) {
            }
        }
    }
}
Онлайн: 0
Реклама