Skip to content

Commit 600cd41

Browse files
committed
[FrameworkBundle] fixed cache:clear command
1 parent 6c08e70 commit 600cd41

File tree

1 file changed

+27
-5
lines changed

1 file changed

+27
-5
lines changed

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

+27-5
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@
2525
*/
2626
class CacheClearCommand extends ContainerAwareCommand
2727
{
28+
protected $name;
29+
2830
/**
2931
* @see Command
3032
*/
@@ -85,13 +87,33 @@ protected function warmup($warmupDir)
8587
$warmer->warmUp($warmupDir);
8688

8789
// fix container files and classes
90+
$regex = '/'.preg_quote($this->getTempKernelSuffix(), '/').'/';
8891
$finder = new Finder();
8992
foreach ($finder->files()->name(get_class($kernel->getContainer()).'*')->in($warmupDir) as $file) {
9093
$content = file_get_contents($file);
91-
$content = preg_replace('/__.*__/', '', $content);
92-
file_put_contents(preg_replace('/__.*__/', '', $file), $content);
94+
$content = preg_replace($regex, '', $content);
95+
file_put_contents(preg_replace($regex, '', $file), $content);
9396
unlink($file);
9497
}
98+
99+
// fix meta references to the Kernel
100+
foreach ($finder->files()->name('*.meta')->in($warmupDir) as $file) {
101+
$content = preg_replace(
102+
'/C\:\d+\:"AppKernel'.preg_quote($this->getTempKernelSuffix(), '"/').'"/',
103+
'C:9:"AppKernel"',
104+
file_get_contents($file)
105+
);
106+
file_put_contents($file, $content);
107+
}
108+
}
109+
110+
protected function getTempKernelSuffix()
111+
{
112+
if (null === $this->name) {
113+
$this->name = '__'.uniqid().'__';
114+
}
115+
116+
return $this->name;
95117
}
96118

97119
protected function getTempKernel(KernelInterface $parent, $warmupDir)
@@ -104,8 +126,8 @@ protected function getTempKernel(KernelInterface $parent, $warmupDir)
104126
$parentClass = substr($parentClass, $pos + 1);
105127
}
106128

107-
$rand = uniqid();
108-
$class = $parentClass.$rand;
129+
$suffix = $this->getTempKernelSuffix();
130+
$class = $parentClass.$suffix;
109131
$rootDir = $parent->getRootDir();
110132
$code = <<<EOF
111133
<?php
@@ -126,7 +148,7 @@ public function getRootDir()
126148
127149
protected function getContainerClass()
128150
{
129-
return parent::getContainerClass().'__{$rand}__';
151+
return parent::getContainerClass().'{$suffix}';
130152
}
131153
}
132154
}

0 commit comments

Comments
 (0)