vendor/symfony/src/Symfony/Bundle/FrameworkBundle/Command/RouterApacheDumperCommand.php
changeset 0 7f95f8617b0b
equal deleted inserted replaced
-1:000000000000 0:7f95f8617b0b
       
     1 <?php
       
     2 
       
     3 /*
       
     4  * This file is part of the Symfony package.
       
     5  *
       
     6  * (c) Fabien Potencier <fabien@symfony.com>
       
     7  *
       
     8  * For the full copyright and license information, please view the LICENSE
       
     9  * file that was distributed with this source code.
       
    10  */
       
    11 
       
    12 namespace Symfony\Bundle\FrameworkBundle\Command;
       
    13 
       
    14 use Symfony\Component\Console\Input\InputArgument;
       
    15 use Symfony\Component\Console\Input\InputOption;
       
    16 use Symfony\Component\Console\Input\InputInterface;
       
    17 use Symfony\Component\Console\Output\OutputInterface;
       
    18 use Symfony\Component\Console\Output\Output;
       
    19 use Symfony\Component\Routing\Matcher\Dumper\ApacheMatcherDumper;
       
    20 
       
    21 /**
       
    22  * RouterApacheDumperCommand.
       
    23  *
       
    24  * @author Fabien Potencier <fabien@symfony.com>
       
    25  */
       
    26 class RouterApacheDumperCommand extends ContainerAwareCommand
       
    27 {
       
    28     /**
       
    29      * @see Command
       
    30      */
       
    31     protected function configure()
       
    32     {
       
    33         $this
       
    34             ->setDefinition(array(
       
    35                 new InputArgument('script_name', InputArgument::OPTIONAL, 'The script name of the application\'s front controller.'),
       
    36                 new InputOption('base-uri', null, InputOption::VALUE_REQUIRED, 'The base URI'),
       
    37             ))
       
    38             ->setName('router:dump-apache')
       
    39             ->setDescription('Dumps all routes as Apache rewrite rules')
       
    40             ->setHelp(<<<EOF
       
    41 The <info>router:dump-apache</info> dumps all routes as Apache rewrite rules.
       
    42 These can then be used with the ApacheUrlMatcher to use Apache for route
       
    43 matching.
       
    44 
       
    45   <info>router:dump-apache</info>
       
    46 EOF
       
    47             )
       
    48         ;
       
    49     }
       
    50 
       
    51     /**
       
    52      * @see Command
       
    53      */
       
    54     protected function execute(InputInterface $input, OutputInterface $output)
       
    55     {
       
    56         $router = $this->getContainer()->get('router');
       
    57 
       
    58         $dumpOptions = array();
       
    59         if ($input->getArgument('script_name')) {
       
    60             $dumpOptions['script_name'] = $input->getArgument('script_name');
       
    61         }
       
    62         if ($input->getOption('base-uri')) {
       
    63             $dumpOptions['base_uri'] = $input->getOption('base-uri');
       
    64         }
       
    65 
       
    66         $dumper = new ApacheMatcherDumper($router->getRouteCollection());
       
    67 
       
    68         $output->writeln($dumper->dump($dumpOptions), OutputInterface::OUTPUT_RAW);
       
    69     }
       
    70 }