diff --git a/src/Symfony/Bundle/FrameworkBundle/Command/CacheClearCommand.php b/src/Symfony/Bundle/FrameworkBundle/Command/CacheClearCommand.php index 8c3ca3c85f44..f60f5ac33015 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Command/CacheClearCommand.php +++ b/src/Symfony/Bundle/FrameworkBundle/Command/CacheClearCommand.php @@ -33,13 +33,16 @@ protected function configure() $this ->setName('cache:clear') ->setDefinition(array( - new InputOption('no-warmup', '', InputOption::VALUE_NONE, 'Do not warm up the cache') + new InputOption('no-warmup', '', InputOption::VALUE_NONE, 'Do not warm up the cache'), + new InputOption('without-debug', '', InputOption::VALUE_NONE, 'If the cache is warmed up, whether to disable debugging or not'), )) ->setDescription('Clear the cache') ->setHelp(<<cache:clear command clears the application cache for the current environment: +The cache:clear command clears the application cache for a given environment +and debug mode: -./app/console cache:clear +./app/console cache:clear dev +./app/console cache:clear prod --without-debug EOF ) ; @@ -54,7 +57,7 @@ protected function execute(InputInterface $input, OutputInterface $output) $oldCacheDir = $realCacheDir.'_old'; if (!is_writable($realCacheDir)) { - throw new \RuntimeException(sprintf('Unable to write in "%s" directory', $this->realCacheDir)); + throw new \RuntimeException(sprintf('Unable to write in the "%s" directory', $this->realCacheDir)); } if ($input->getOption('no-warmup')) { @@ -62,7 +65,7 @@ protected function execute(InputInterface $input, OutputInterface $output) } else { $warmupDir = $realCacheDir.'_new'; - $this->warmup($warmupDir); + $this->warmup(!$input->getOption('without-debug'), $warmupDir); rename($realCacheDir, $oldCacheDir); rename($warmupDir, $realCacheDir); @@ -71,18 +74,18 @@ protected function execute(InputInterface $input, OutputInterface $output) $this->container->get('filesystem')->remove($oldCacheDir); } - protected function warmup($warmupDir) + protected function warmup($debug, $warmupDir) { $this->container->get('filesystem')->remove($warmupDir); - $kernel = $this->getTempKernel($this->container->get('kernel'), $warmupDir); + $kernel = $this->getTempKernel($this->container->get('kernel'), $debug, $warmupDir); $kernel->boot(); $warmer = $kernel->getContainer()->get('cache_warmer'); $warmer->enableOptionalWarmers(); $warmer->warmUp($warmupDir); - // rename container files + // fix container files and classes $finder = new Finder(); foreach ($finder->files()->name(get_class($kernel->getContainer()).'*')->in($warmupDir) as $file) { $content = file_get_contents($file); @@ -92,7 +95,7 @@ protected function warmup($warmupDir) } } - protected function getTempKernel(KernelInterface $parent, $warmupDir) + protected function getTempKernel(KernelInterface $parent, $debug, $warmupDir) { $parentClass = get_class($parent); $rand = uniqid(); @@ -124,6 +127,6 @@ protected function getContainerClass() require_once $file; @unlink($file); - return new $class($parent->getEnvironment(), $parent->isDebug()); + return new $class($parent->getEnvironment(), $debug); } }