From 9cd15908f374d274c671157289d2f5086a5c236e Mon Sep 17 00:00:00 2001 From: Fabien Potencier Date: Sun, 26 Jun 2011 18:34:40 +0200 Subject: [PATCH] [FrameworkBundle] fixed cache:clear command when the kernel class is not AppKernel --- .../Command/CacheClearCommand.php | 32 +++++++++---------- 1 file changed, 15 insertions(+), 17 deletions(-) diff --git a/src/Symfony/Bundle/FrameworkBundle/Command/CacheClearCommand.php b/src/Symfony/Bundle/FrameworkBundle/Command/CacheClearCommand.php index 08ad3021ea..aa1295540b 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Command/CacheClearCommand.php +++ b/src/Symfony/Bundle/FrameworkBundle/Command/CacheClearCommand.php @@ -79,7 +79,15 @@ EOF { $this->getContainer()->get('filesystem')->remove($warmupDir); - $kernel = $this->getTempKernel($this->getContainer()->get('kernel'), $warmupDir); + $parent = $this->getContainer()->get('kernel'); + $class = get_class($parent); + $namespace = ''; + if (false !== $pos = strrpos($class, '\\')) { + $namespace = substr($class, 0, $pos); + $class = substr($class, $pos + 1); + } + + $kernel = $this->getTempKernel($parent, $namespace, $class, $warmupDir); $kernel->boot(); $warmer = $kernel->getContainer()->get('cache_warmer'); @@ -99,8 +107,8 @@ EOF // fix meta references to the Kernel foreach ($finder->files()->name('*.meta')->in($warmupDir) as $file) { $content = preg_replace( - '/C\:\d+\:"AppKernel'.preg_quote($this->getTempKernelSuffix(), '"/').'"/', - 'C:9:"AppKernel"', + '/C\:\d+\:"'.preg_quote($class.$this->getTempKernelSuffix(), '"/').'"/', + sprintf('C:%s:"%s"', strlen($class), $class), file_get_contents($file) ); file_put_contents($file, $content); @@ -116,25 +124,16 @@ EOF return $this->name; } - protected function getTempKernel(KernelInterface $parent, $warmupDir) + protected function getTempKernel(KernelInterface $parent, $namespace, $class, $warmupDir) { - $parentClass = get_class($parent); - - $namespace = ''; - if (false !== $pos = strrpos($parentClass, '\\')) { - $namespace = substr($parentClass, 0, $pos); - $parentClass = substr($parentClass, $pos + 1); - } - $suffix = $this->getTempKernelSuffix(); - $class = $parentClass.$suffix; $rootDir = $parent->getRootDir(); $code = <<getEnvironment(), $parent->isDebug()); }