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 ;
2012-06-09 21:15:29 +01:00
use Symfony\Component\ClassLoader\ClassCollectionLoader ;
2011-01-24 10:16:22 +00:00
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
{
/**
* @ see Command
*/
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 .
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-06-09 21:15:29 +01:00
$cacheDir = $this -> getContainer () -> getParameter ( 'kernel.cache_dir' );
$warmer -> warmUp ( $cacheDir );
$classmap = $cacheDir . '/classes.map' ;
if ( is_file ( $classmap )) {
ClassCollectionLoader :: load ( include ( $classmap ), $cacheDir , 'classes' , $kernel -> isDebug (), false , '.php' );
}
2011-03-21 08:52:39 +00:00
}
2011-01-24 10:16:22 +00:00
}