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
*
2014-12-29 23:26:56 +00:00
* @ deprecated since version 2.5 , to be removed in 3.0 .
2014-01-08 22:03:56 +00:00
* The performance gains are minimal and it ' s very hard to replicate
* the behavior of PHP implementation .
*
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
/**
2013-03-07 13:36:36 +00:00
* { @ inheritdoc }
2011-06-28 23:18:41 +01:00
*/
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
/**
2013-03-07 13:36:36 +00:00
* { @ inheritdoc }
2010-05-06 12:25:53 +01:00
*/
protected function configure ()
{
$this
2012-02-12 15:37:55 +00:00
-> setName ( 'router:dump-apache' )
2010-11-26 20:02:16 +00:00
-> setDefinition ( array (
2015-01-04 09:47:47 +00:00
new InputArgument ( 'script_name' , InputArgument :: OPTIONAL , 'The script name of the application\'s front controller' ),
2011-03-21 12:58:02 +00:00
new InputOption ( 'base-uri' , null , InputOption :: VALUE_REQUIRED , 'The base URI' ),
2010-11-26 20:02:16 +00:00
))
2014-11-29 10:10:30 +00:00
-> setDescription ( '[DEPRECATED] Dumps all routes as Apache rewrite rules' )
2010-11-26 20:02:16 +00:00
-> setHelp ( <<< EOF
2012-02-12 15:37:55 +00:00
The < info >% command . name %</ info > dumps all routes as Apache rewrite rules .
2010-11-26 20:02:16 +00:00
These can then be used with the ApacheUrlMatcher to use Apache for route
matching .
2012-02-12 15:37:55 +00:00
< info > php % command . full_name %</ info >
2014-03-13 04:05:55 +00:00
2010-11-26 20:02:16 +00:00
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
/**
2013-03-07 13:36:36 +00:00
* { @ inheritdoc }
2010-05-06 12:25:53 +01:00
*/
protected function execute ( InputInterface $input , OutputInterface $output )
{
2015-01-04 00:21:40 +00:00
$formatter = $this -> getHelper ( 'formatter' );
$output -> writeln ( $formatter -> formatSection ( 'warning' , 'The router:dump-apache command is deprecated since version 2.5 and will be removed in 3.0' , 'comment' ));
2014-11-29 10:10:30 +00:00
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
}