2011-01-24 10:16:22 +00:00
< ? php
/*
* This file is part of the Symfony package .
*
2011-03-06 11:40:06 +00:00
* ( c ) Fabien Potencier < fabien @ symfony . com >
2011-01-24 10:16:22 +00:00
*
* 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\Component\Console\Input\InputInterface ;
2012-02-09 00:44:27 +00:00
use Symfony\Component\Console\Input\InputOption ;
2011-01-24 10:16:22 +00:00
use Symfony\Component\Console\Output\OutputInterface ;
/**
* Warmup the cache .
*
2011-03-06 11:40:06 +00:00
* @ author Fabien Potencier < fabien @ symfony . com >
2011-01-24 10:16:22 +00:00
*/
2011-06-20 20:04:55 +01:00
class CacheWarmupCommand extends ContainerAwareCommand
2011-01-24 10:16:22 +00:00
{
/**
2013-03-07 13:36:36 +00:00
* { @ inheritdoc }
2011-01-24 10:16:22 +00:00
*/
protected function configure ()
{
$this
-> setName ( 'cache:warmup' )
2012-02-09 00:44:27 +00:00
-> setDefinition ( array (
new InputOption ( 'no-optional-warmers' , '' , InputOption :: VALUE_NONE , 'Skip optional cache warmers (faster)' ),
))
2011-01-24 10:16:22 +00:00
-> setDescription ( 'Warms up an empty cache' )
-> setHelp ( <<< EOF
2012-02-12 15:37:55 +00:00
The < info >% command . name %</ info > command warms up the cache .
2011-01-24 10:16:22 +00:00
2011-03-21 08:46:44 +00:00
Before running this command , the cache must be empty .
2012-07-05 07:00:39 +01:00
This command does not generate the classes cache ( as when executing this
command , too many classes that should be part of the cache are already loaded
in memory ) . Use < comment > curl </ comment > or any other similar tool to warm up
the classes cache if you want .
2014-03-13 04:05:55 +00:00
2011-01-24 10:16:22 +00:00
EOF
)
;
}
/**
* { @ inheritdoc }
*/
protected function execute ( InputInterface $input , OutputInterface $output )
{
2012-01-29 21:53:47 +00:00
$kernel = $this -> getContainer () -> get ( 'kernel' );
$output -> writeln ( sprintf ( 'Warming up the cache for the <info>%s</info> environment with debug <info>%s</info>' , $kernel -> getEnvironment (), var_export ( $kernel -> isDebug (), true )));
2011-01-24 10:16:22 +00:00
2011-06-20 20:04:55 +01:00
$warmer = $this -> getContainer () -> get ( 'cache_warmer' );
2012-02-09 00:44:27 +00:00
if ( ! $input -> getOption ( 'no-optional-warmers' )) {
$warmer -> enableOptionalWarmers ();
}
2012-07-05 06:56:11 +01:00
$warmer -> warmUp ( $this -> getContainer () -> getParameter ( 'kernel.cache_dir' ));
2011-03-21 08:52:39 +00:00
}
2011-01-24 10:16:22 +00:00
}