8000 [FrameworkBundle] added --without-debug option to cache:clear as the … · dpb587/symfony@85778ca · GitHub
[go: up one dir, main page]

Skip to content

Commit 85778ca

Browse files
committed
[FrameworkBundle] added --without-debug option to cache:clear as the debug flag value can be different from the one used for the command execution (think generating the prod cache but still with debug information when running the command)
1 parent e4a636a commit 85778ca

File tree

1 file changed

+13
-10
lines changed

1 file changed

+13
-10
lines changed

src/Symfony/Bundle/FrameworkBundle/Command/CacheClearCommand.php

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -33,13 +33,16 @@ protected function configure()
3333
$this
3434
->setName('cache:clear')
3535
->setDefinition(array(
36-
new InputOption('no-warmup', '', InputOption::VALUE_NONE, 'Do not warm up the cache')
36+
new InputOption('no-warmup', '', InputOption::VALUE_NONE, 'Do not warm up the cache'),
37+
new InputOption('without-debug', '', InputOption::VALUE_NONE, 'If the cache is warmed up, whether to disable debugging or not'),
3738
))
3839
->setDescription('Clear the cache')
3940
->setHelp(<<<EOF
40-
The <info>cache:clear</info> command clears the application cache for the current environment:
41+
The <info>cache:clear</info> command clears the application cache for a given environment
42+
and debug mode:
4143
42-
<info>./app/console cache:clear</info>
44+
<info>./app/console cache:clear dev</info>
45+
<info>./app/console cache:clear prod --without-debug</info>
4346
EOF
4447
)
4548
;
@@ -54,15 +57,15 @@ protected function execute(InputInterface $input, OutputInterface $output)
5457
$oldCacheDir = $realCacheDir.'_old';
5558

5659
if (!is_writable($realCacheDir)) {
57-
throw new \RuntimeException(sprintf('Unable to write in "%s" directory', $this->realCacheDir));
60+
throw new \RuntimeException(sprintf('Unable to write in the "%s" directory', $this->realCacheDir));
5861
}
5962

6063
if ($input->getOption('no-warmup')) {
6164
rename($realCacheDir, $oldCacheDir);
6265
} else {
6366
$warmupDir = $realCacheDir.'_new';
6467

65-
$this->warmup($warmupDir);
68+
$this->warmup(!$input->getOption('without-debug'), $warmupDir);
6669

6770
rename($realCacheDir, $oldCacheDir);
6871
rename($warmupDir, $realCacheDir);
@@ -71,18 +74,18 @@ protected function execute(InputInterface $input, OutputInterface $output)
7174
$this->container->get('filesystem')->remove($oldCacheDir);
7275
}
7376

74-
protected function warmup($warmupDir)
77+
protected function warmup($debug, $warmupDir)
7578
{
7679
$this->container->get('filesystem')->remove($warmupDir);
7780

78-
$kernel = $this->getTempKernel($this->container->get('kernel'), $warmupDir);
81+
$kernel = $this->getTempKernel($this->container->get('kernel'), $debug, $warmupDir);
7982
$kernel->boot();
8083

8184
$warmer = $kernel->getContainer()->get('cache_warmer');
8285
$warmer->enableOptionalWarmers();
8386
$warmer->warmUp($warmupDir);
8487

85-
// rename container files
88+
// fix container files and classes
8689
$finder = new Finder();
8790
foreach ($finder->files()->name(get_class($kernel->getContainer()).'*')->in($warmupDir) as $file) {
8891
$content = file_get_contents($file);
@@ -92,7 +95,7 @@ protected function warmup($warmupDir)
9295
}
9396
}
9497

95-
protected function getTempKernel(KernelInterface $parent, $warmupDir)
98+
protected function getTempKernel(KernelInterface $parent, $debug, $warmupDir)
9699
{
97100
$parentClass = get_class($parent);
98101
$rand = uniqid();
@@ -124,6 +127,6 @@ protected function getContainerClass()
124127
require_once $file;
125128
@unlink($file);
126129

127-
return new $class($parent->getEnvironment(), $parent->isDebug());
130+
return new $class($parent->getEnvironment(), $debug);
128131
}
129132
}

0 commit comments

Comments
 (0)
0