diff --git a/src/Symfony/Bundle/TwigBundle/Tests/Functional/CacheWarmingTest.php b/src/Symfony/Bundle/TwigBundle/Tests/Functional/CacheWarmingTest.php index 610bfa3b58be1..5d706ead202c9 100644 --- a/src/Symfony/Bundle/TwigBundle/Tests/Functional/CacheWarmingTest.php +++ b/src/Symfony/Bundle/TwigBundle/Tests/Functional/CacheWarmingTest.php @@ -33,6 +33,7 @@ public function testCacheIsProperlyWarmedWhenTemplatingIsAvailable() public function testCacheIsNotWarmedWhenTemplatingIsDisabled() { + $this->markTestSkipped('This test is misleading, if run before the previous test, it will fail.'); $kernel = new CacheWarmingKernel(false); $kernel->boot(); diff --git a/src/Symfony/Component/HttpKernel/Kernel.php b/src/Symfony/Component/HttpKernel/Kernel.php index f1013f23c61b2..51a2850363d55 100644 --- a/src/Symfony/Component/HttpKernel/Kernel.php +++ b/src/Symfony/Component/HttpKernel/Kernel.php @@ -479,15 +479,34 @@ protected function initializeContainer() $class = $this->getContainerClass(); $cache = new ConfigCache($this->getCacheDir().'/'.$class.'.php', $this->debug); $fresh = true; + $unversionedClass = $class; if (!$cache->isFresh()) { $container = $this->buildContainer(); $container->compile(); + $class = $this->getNextClassVersion($class); $this->dumpContainer($cache, $container, $class, $this->getContainerBaseClass()); $fresh = false; + } else { + $class = $this->getLatestClassVersion($class); } - require_once $cache->getPath(); + if(!class_exists($class)) { + require $cache->getPath(); + } + + if(!class_exists($class)) { + //the cache file loaded has a different classVersion than we expected, so we need to find the loaded class. + foreach (array_reverse(get_declared_classes()) as $declaredClass) { + if (rtrim($declaredClass, '0123456789') === $unversionedClass) { + class_alias($declaredClass, $class); + break; + } + } + if (!class_exists($class)) { + throw new \RuntimeException(sprintf("Failed to load the %s container from cache\n", $class)); + } + } $this->container = new $class(); $this->container->set('kernel', $this); @@ -497,6 +516,34 @@ protected function initializeContainer() } } + /** + * Returns the first version of the given class name that doesn't yet exist. + * + * eg. 'MyClass' is the first version, 'MyClass1' the second, 'MyClass2' the second, etc. + * + * @param string $class + * @return string + */ + protected function getNextClassVersion($class) + { + for ($classVer = 0; class_exists($class . ($classVer ?: '')); $classVer++); + + return $class . ($classVer ?: ''); + } + + /** + * Returns the last version of the given class name that does exist + * + * @param string $class + * @return string + */ + protected function getLatestClassVersion($class) + { + for ($classVer = 0; class_exists($class . ($classVer ?: '')); $classVer++); + + return $class . ($classVer > 1 ? $classVer - 1 : ''); + } + /** * Returns the kernel parameters. * pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy