From d1f5d254838fecf25cbec07947c84cee2bc465b2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jean-Fran=C3=A7ois=20Simon?= Date: Fri, 1 Mar 2013 17:33:44 +0100 Subject: [PATCH] [FrameworkBundle] Fixes invalid serialized objects in cache --- .../Command/CacheClearCommand.php | 35 ++++++++++++------- .../FrameworkExtension.php | 2 +- .../Resources/config/routing.xml | 4 +-- 3 files changed, 26 insertions(+), 15 deletions(-) diff --git a/src/Symfony/Bundle/FrameworkBundle/Command/CacheClearCommand.php b/src/Symfony/Bundle/FrameworkBundle/Command/CacheClearCommand.php index a9aa7a5b8f..99a0f2e88c 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Command/CacheClearCommand.php +++ b/src/Symfony/Bundle/FrameworkBundle/Command/CacheClearCommand.php @@ -104,10 +104,31 @@ EOF $warmer->warmUp($warmupDir); + foreach (Finder::create()->files()->name('*.meta')->in($warmupDir) as $file) { + // fix meta references to the Kernel + $content = preg_replace( + '/C\:\d+\:"'.preg_quote($class.$this->getTempKernelSuffix(), '"/').'"/', + sprintf('C:%s:"%s"', strlen($class), $class), + file_get_contents($file) + ); + + // fix meta references to cache files + $realWarmupDir = substr($warmupDir, 0, -4); + $content = preg_replace_callback( + '/s\:\d+\:"'.preg_quote($warmupDir, '/').'([^"]+)"/', + function (array $matches) use ($realWarmupDir) { + $path = $realWarmupDir.$matches[1]; + return sprintf('s:%s:"%s"', strlen($path), $path); + }, + $content + ); + + file_put_contents($file, $content); + } + // fix container files and classes $regex = '/'.preg_quote($this->getTempKernelSuffix(), '/').'/'; - $finder = new Finder(); - foreach ($finder->files()->name(get_class($kernel->getContainer()).'*')->in($warmupDir) as $file) { + foreach (Finder::create()->files()->name(get_class($kernel->getContainer()).'*')->in($warmupDir) as $file) { $content = file_get_contents($file); $content = preg_replace($regex, '', $content); @@ -117,16 +138,6 @@ EOF file_put_contents(preg_replace($regex, '', $file), $content); unlink($file); } - - // fix meta references to the Kernel - foreach ($finder->files()->name('*.meta')->in($warmupDir) as $file) { - $content = preg_replace( - '/C\:\d+\:"'.preg_quote($class.$this->getTempKernelSuffix(), '"/').'"/', - sprintf('C:%s:"%s"', strlen($class), $class), - file_get_contents($file) - ); - file_put_contents($file, $content); - } } protected function getTempKernelSuffix() diff --git a/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/FrameworkExtension.php b/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/FrameworkExtension.php index 0b69d8c9c2..0399249d4d 100644 --- a/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/FrameworkExtension.php +++ b/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/FrameworkExtension.php @@ -246,8 +246,8 @@ class FrameworkExtension extends Extension $loader->load('routing.xml'); $container->setParameter('router.resource', $config['resource']); + $container->setParameter('router.cache_class_prefix', $container->getParameter('kernel.name').ucfirst($container->getParameter('kernel.environment'))); $router = $container->findDefinition('router.default'); - $argument = $router->getArgument(2); $argument['strict_requirements'] = $config['strict_requirements']; if (isset($config['type'])) { diff --git a/src/Symfony/Bundle/FrameworkBundle/Resources/config/routing.xml b/src/Symfony/Bundle/FrameworkBundle/Resources/config/routing.xml index ff6c6f5851..339e17f66e 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Resources/config/routing.xml +++ b/src/Symfony/Bundle/FrameworkBundle/Resources/config/routing.xml @@ -19,8 +19,8 @@ Symfony\Bundle\FrameworkBundle\Routing\RedirectableUrlMatcher Symfony\Component\Routing\Matcher\Dumper\PhpMatcherDumper Symfony\Bundle\FrameworkBundle\CacheWarmer\RouterCacheWarmer - %kernel.name%%kernel.environment%UrlMatcher - %kernel.name%%kernel.environment%UrlGenerator + %router.cache_class_prefix%UrlMatcher + %router.cache_class_prefix%UrlGenerator Symfony\Component\HttpKernel\EventListener\RouterListener localhost http