[HttpKernel] made the classmap lazy-loaded
This commit is contained in:
parent
ea252671b0
commit
2aefe211df
@ -60,6 +60,7 @@ abstract class Kernel implements KernelInterface, TerminableInterface
|
||||
protected $name;
|
||||
protected $startTime;
|
||||
protected $classes;
|
||||
protected $loadClassCache;
|
||||
protected $errorReportingLevel;
|
||||
|
||||
const VERSION = '2.3.0-DEV';
|
||||
@ -132,6 +133,10 @@ abstract class Kernel implements KernelInterface, TerminableInterface
|
||||
return;
|
||||
}
|
||||
|
||||
if (!empty($this->loadClassCache)) {
|
||||
call_user_func_array(array($this, 'doLoadClassCache'), $this->loadClassCache);
|
||||
}
|
||||
|
||||
// init bundles
|
||||
$this->initializeBundles();
|
||||
|
||||
@ -403,9 +408,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);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -456,6 +459,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.
|
||||
*
|
||||
|
@ -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')
|
||||
|
Reference in New Issue
Block a user