2010-02-17 13:55:05 +00:00
|
|
|
<?php
|
|
|
|
|
2011-01-15 13:29:43 +00:00
|
|
|
/*
|
|
|
|
* This file is part of the Symfony package.
|
|
|
|
*
|
2011-03-06 11:40:06 +00:00
|
|
|
* (c) Fabien Potencier <fabien@symfony.com>
|
2011-01-15 13:29:43 +00:00
|
|
|
*
|
|
|
|
* For the full copyright and license information, please view the LICENSE
|
|
|
|
* file that was distributed with this source code.
|
|
|
|
*/
|
|
|
|
|
2010-07-09 09:05:26 +01:00
|
|
|
namespace Symfony\Bundle\FrameworkBundle\Command;
|
2010-02-17 13:55:05 +00:00
|
|
|
|
2010-08-20 22:09:55 +01:00
|
|
|
use Symfony\Component\Console\Input\InputArgument;
|
|
|
|
use Symfony\Component\Console\Input\InputOption;
|
|
|
|
use Symfony\Component\Console\Input\InputInterface;
|
|
|
|
use Symfony\Component\Console\Output\OutputInterface;
|
|
|
|
use Symfony\Component\Routing\Matcher\Dumper\ApacheMatcherDumper;
|
2011-10-16 12:56:51 +01:00
|
|
|
use Symfony\Component\Routing\RouterInterface;
|
2010-02-17 13:55:05 +00:00
|
|
|
|
|
|
|
/**
|
2010-04-07 01:51:29 +01:00
|
|
|
* RouterApacheDumperCommand.
|
2010-02-17 13:55:05 +00:00
|
|
|
*
|
2011-03-06 11:40:06 +00:00
|
|
|
* @author Fabien Potencier <fabien@symfony.com>
|
2010-02-17 13:55:05 +00:00
|
|
|
*/
|
2011-06-20 20:04:55 +01:00
|
|
|
class RouterApacheDumperCommand extends ContainerAwareCommand
|
2010-02-17 13:55:05 +00:00
|
|
|
{
|
2011-06-28 23:18:41 +01:00
|
|
|
/**
|
|
|
|
* {@inheritDoc}
|
|
|
|
*/
|
|
|
|
public function isEnabled()
|
|
|
|
{
|
|
|
|
if (!$this->getContainer()->has('router')) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
$router = $this->getContainer()->get('router');
|
2011-10-16 12:56:51 +01:00
|
|
|
if (!$router instanceof RouterInterface) {
|
2011-06-28 23:18:41 +01:00
|
|
|
return false;
|
|
|
|
}
|
2011-10-29 11:05:45 +01:00
|
|
|
|
2011-06-28 23:18:41 +01:00
|
|
|
return parent::isEnabled();
|
|
|
|
}
|
|
|
|
|
2010-05-06 12:25:53 +01:00
|
|
|
/**
|
|
|
|
* @see Command
|
|
|
|
*/
|
|
|
|
protected function configure()
|
|
|
|
{
|
|
|
|
$this
|
2010-11-26 20:02:16 +00:00
|
|
|
->setDefinition(array(
|
2011-03-21 12:58:02 +00:00
|
|
|
new InputArgument('script_name', InputArgument::OPTIONAL, 'The script name of the application\'s front controller.'),
|
|
|
|
new InputOption('base-uri', null, InputOption::VALUE_REQUIRED, 'The base URI'),
|
2010-11-26 20:02:16 +00:00
|
|
|
))
|
2010-05-06 12:25:53 +01:00
|
|
|
->setName('router:dump-apache')
|
2010-11-26 20:02:16 +00:00
|
|
|
->setDescription('Dumps all routes as Apache rewrite rules')
|
|
|
|
->setHelp(<<<EOF
|
|
|
|
The <info>router:dump-apache</info> dumps all routes as Apache rewrite rules.
|
|
|
|
These can then be used with the ApacheUrlMatcher to use Apache for route
|
|
|
|
matching.
|
|
|
|
|
|
|
|
<info>router:dump-apache</info>
|
|
|
|
EOF
|
|
|
|
)
|
2010-05-06 12:25:53 +01:00
|
|
|
;
|
|
|
|
}
|
2010-02-17 13:55:05 +00:00
|
|
|
|
2010-05-06 12:25:53 +01:00
|
|
|
/**
|
|
|
|
* @see Command
|
|
|
|
*/
|
|
|
|
protected function execute(InputInterface $input, OutputInterface $output)
|
|
|
|
{
|
2011-06-20 20:04:55 +01:00
|
|
|
$router = $this->getContainer()->get('router');
|
2010-02-17 13:55:05 +00:00
|
|
|
|
2010-11-26 20:02:16 +00:00
|
|
|
$dumpOptions = array();
|
|
|
|
if ($input->getArgument('script_name')) {
|
|
|
|
$dumpOptions['script_name'] = $input->getArgument('script_name');
|
|
|
|
}
|
2011-03-21 12:58:02 +00:00
|
|
|
if ($input->getOption('base-uri')) {
|
|
|
|
$dumpOptions['base_uri'] = $input->getOption('base-uri');
|
|
|
|
}
|
2010-11-26 20:02:16 +00:00
|
|
|
|
2010-05-06 12:25:53 +01:00
|
|
|
$dumper = new ApacheMatcherDumper($router->getRouteCollection());
|
2010-02-17 13:55:05 +00:00
|
|
|
|
2011-03-29 20:53:28 +01:00
|
|
|
$output->writeln($dumper->dump($dumpOptions), OutputInterface::OUTPUT_RAW);
|
2010-05-06 12:25:53 +01:00
|
|
|
}
|
2010-02-17 13:55:05 +00:00
|
|
|
}
|