diff --git a/src/Symfony/Component/HttpKernel/Kernel.php b/src/Symfony/Component/HttpKernel/Kernel.php index 17d56823c0..9e88498e11 100644 --- a/src/Symfony/Component/HttpKernel/Kernel.php +++ b/src/Symfony/Component/HttpKernel/Kernel.php @@ -57,6 +57,7 @@ abstract class Kernel implements KernelInterface, TerminableInterface protected $name; protected $startTime; protected $classes; + protected $loadClassCache; const VERSION = '2.3.0-DEV'; const VERSION_ID = '20300'; @@ -118,6 +119,10 @@ abstract class Kernel implements KernelInterface, TerminableInterface return; } + if ($this->loadClassCache) { + call_user_func_array(array($this, 'doLoadClassCache', $this->loadClassCache); + } + // init bundles $this->initializeBundles(); @@ -389,9 +394,7 @@ abstract class Kernel implements KernelInterface, TerminableInterface */ public function loadClassCache($name = 'classes', $extension = '.php') { - if (!$this->booted && is_file($this->getCacheDir().'/classes.map')) { - ClassCollectionLoader::load(include($this->getCacheDir().'/classes.map'), $this->getCacheDir(), $name, $this->debug, false, $extension); - } + $this->loadClassCache = array($name, $extension); } /** @@ -442,6 +445,13 @@ abstract class Kernel implements KernelInterface, TerminableInterface return 'UTF-8'; } + protected function doLoadClassCache($name, $extension) + { + if (!$this->booted && is_file($this->getCacheDir().'/classes.map')) { + ClassCollectionLoader::load(include($this->getCacheDir().'/classes.map'), $this->getCacheDir(), $name, $this->debug, false, $extension); + } + } + /** * Initializes the data structures related to the bundle management. * diff --git a/src/Symfony/Component/HttpKernel/Tests/KernelTest.php b/src/Symfony/Component/HttpKernel/Tests/KernelTest.php index d4295f5ab8..4a25089ca1 100644 --- a/src/Symfony/Component/HttpKernel/Tests/KernelTest.php +++ b/src/Symfony/Component/HttpKernel/Tests/KernelTest.php @@ -108,6 +108,52 @@ class KernelTest extends \PHPUnit_Framework_TestCase $this->assertTrue($kernel->isBooted()); } + public function testClassCacheIsLoaded() + { + $kernel = $this->getMockBuilder('Symfony\Component\HttpKernel\Tests\Fixtures\KernelForTest') + ->disableOriginalConstructor() + ->setMethods(array('initializeBundles', 'initializeContainer', 'getBundles', 'doLoadClassCache')) + ->getMock(); + $kernel->loadClassCache('name', '.extension'); + $kernel->expects($this->any()) + ->method('getBundles') + ->will($this->returnValue(array())); + $kernel->expects($this->once()) + ->method('doLoadClassCache') + ->with('name', '.extension'); + + $kernel->boot(); + } + + public function testClassCacheIsNotLoadedByDefault() + { + $kernel = $this->getMockBuilder('Symfony\Component\HttpKernel\Tests\Fixtures\KernelForTest') + ->disableOriginalConstructor() + ->setMethods(array('initializeBundles', 'initializeContainer', 'getBundles', 'doLoadClassCache')) + ->getMock(); + $kernel->expects($this->any()) + ->method('getBundles') + ->will($this->returnValue(array())); + $kernel->expects($this->never()) + ->method('doLoadClassCache'); + + $kernel->boot(); + } + + public function testClassCacheIsNotLoadedWhenKernelIsNotBooted() + { + $kernel = $this->getMockBuilder('Symfony\Component\HttpKernel\Tests\Fixtures\KernelForTest') + ->disableOriginalConstructor() + ->setMethods(array('initializeBundles', 'initializeContainer', 'getBundles', 'doLoadClassCache')) + ->getMock(); + $kernel->loadClassCache(); + $kernel->expects($this->any()) + ->method('getBundles') + ->will($this->returnValue(array())); + $kernel->expects($this->never()) + ->method('doLoadClassCache'); + } + public function testBootKernelSeveralTimesOnlyInitializesBundlesOnce() { $kernel = $this->getMockBuilder('Symfony\Component\HttpKernel\Tests\Fixtures\KernelForTest')