From f09789b1929d2419056fa6a8182bfe515a92e7ab Mon Sep 17 00:00:00 2001 From: Jordan Alliot Date: Sat, 9 Jun 2012 22:15:29 +0200 Subject: [PATCH] [FrameworkBundle] Generate the class cache when warming up the cache --- src/Symfony/Bundle/FrameworkBundle/CHANGELOG.md | 2 ++ .../FrameworkBundle/Command/CacheClearCommand.php | 14 +++++++++++++- .../FrameworkBundle/Command/CacheWarmupCommand.php | 9 ++++++++- 3 files changed, 23 insertions(+), 2 deletions(-) diff --git a/src/Symfony/Bundle/FrameworkBundle/CHANGELOG.md b/src/Symfony/Bundle/FrameworkBundle/CHANGELOG.md index a8c5b97794..faf11c0a49 100644 --- a/src/Symfony/Bundle/FrameworkBundle/CHANGELOG.md +++ b/src/Symfony/Bundle/FrameworkBundle/CHANGELOG.md @@ -31,3 +31,5 @@ CHANGELOG `gc_probability`/`gc_divisor` chance of being run. The `gc_maxlifetime` defines how long a session can idle for. It is different from cookie lifetime which declares how long a cookie can be stored on the remote client. + * Commands cache:warmup and cache:clear (unless --no-warmup is specified) now + create the class cache. diff --git a/src/Symfony/Bundle/FrameworkBundle/Command/CacheClearCommand.php b/src/Symfony/Bundle/FrameworkBundle/Command/CacheClearCommand.php index a9aa7a5b8f..9a86c75a3e 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Command/CacheClearCommand.php +++ b/src/Symfony/Bundle/FrameworkBundle/Command/CacheClearCommand.php @@ -11,6 +11,7 @@ namespace Symfony\Bundle\FrameworkBundle\Command; +use Symfony\Component\ClassLoader\ClassCollectionLoader; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Input\InputOption; use Symfony\Component\Console\Output\OutputInterface; @@ -63,7 +64,8 @@ EOF } $kernel = $this->getContainer()->get('kernel'); - $output->writeln(sprintf('Clearing the cache for the %s environment with debug %s', $kernel->getEnvironment(), var_export($kernel->isDebug(), true))); + $debug = $kernel->isDebug(); + $output->writeln(sprintf('Clearing the cache for the %s environment with debug %s', $kernel->getEnvironment(), var_export($debug, true))); $this->getContainer()->get('cache_clearer')->clear($realCacheDir); @@ -76,11 +78,21 @@ EOF rename($realCacheDir, $oldCacheDir); rename($warmupDir, $realCacheDir); + + $this->createClassCache($realCacheDir, $debug); } $this->getContainer()->get('filesystem')->remove($oldCacheDir); } + protected function createClassCache($cacheDir, $debug) + { + $classmap = $cacheDir.'/classes.map'; + if (is_file($classmap)) { + ClassCollectionLoader::load(include($classmap), $cacheDir, 'classes', $debug, false, '.php'); + } + } + protected function warmup($warmupDir, $enableOptionalWarmers = true) { $this->getContainer()->get('filesystem')->remove($warmupDir); diff --git a/src/Symfony/Bundle/FrameworkBundle/Command/CacheWarmupCommand.php b/src/Symfony/Bundle/FrameworkBundle/Command/CacheWarmupCommand.php index e997e55df7..11594764ff 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Command/CacheWarmupCommand.php +++ b/src/Symfony/Bundle/FrameworkBundle/Command/CacheWarmupCommand.php @@ -11,6 +11,7 @@ namespace Symfony\Bundle\FrameworkBundle\Command; +use Symfony\Component\ClassLoader\ClassCollectionLoader; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Input\InputOption; use Symfony\Component\Console\Output\OutputInterface; @@ -56,6 +57,12 @@ EOF $warmer->enableOptionalWarmers(); } - $warmer->warmUp($this->getContainer()->getParameter('kernel.cache_dir')); + $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'); + } } }