merged branch bamarni/http-kernel-lazy-classmap (PR #7322)
This PR was merged into the master branch.
Discussion
----------
[HttpKernel] made the classmap lazy-loaded
| Q | A
| ------------- | ---
| Bug fix? | [no]
| New feature? | [yes]
| BC breaks? | [no]
| Deprecations? | [no]
| Tests pass? | [yes]
| License | MIT
see https://github.com/symfony/symfony-standard/pull/437#issuecomment-14667140
Instead of managing this from HttpCache, I suggest to handle it at Kernel's level, what do you think?
Commits
-------
2aefe21
[HttpKernel] made the classmap lazy-loaded
This commit is contained in:
commit
5ad5a5ca48
@ -57,6 +57,7 @@ abstract class Kernel implements KernelInterface, TerminableInterface
|
|||||||
protected $name;
|
protected $name;
|
||||||
protected $startTime;
|
protected $startTime;
|
||||||
protected $classes;
|
protected $classes;
|
||||||
|
protected $loadClassCache;
|
||||||
|
|
||||||
const VERSION = '2.3.0-DEV';
|
const VERSION = '2.3.0-DEV';
|
||||||
const VERSION_ID = '20300';
|
const VERSION_ID = '20300';
|
||||||
@ -118,6 +119,10 @@ abstract class Kernel implements KernelInterface, TerminableInterface
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if ($this->loadClassCache) {
|
||||||
|
call_user_func_array(array($this, 'doLoadClassCache', $this->loadClassCache);
|
||||||
|
}
|
||||||
|
|
||||||
// init bundles
|
// init bundles
|
||||||
$this->initializeBundles();
|
$this->initializeBundles();
|
||||||
|
|
||||||
@ -389,9 +394,7 @@ abstract class Kernel implements KernelInterface, TerminableInterface
|
|||||||
*/
|
*/
|
||||||
public function loadClassCache($name = 'classes', $extension = '.php')
|
public function loadClassCache($name = 'classes', $extension = '.php')
|
||||||
{
|
{
|
||||||
if (!$this->booted && is_file($this->getCacheDir().'/classes.map')) {
|
$this->loadClassCache = array($name, $extension);
|
||||||
ClassCollectionLoader::load(include($this->getCacheDir().'/classes.map'), $this->getCacheDir(), $name, $this->debug, false, $extension);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -442,6 +445,13 @@ abstract class Kernel implements KernelInterface, TerminableInterface
|
|||||||
return 'UTF-8';
|
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.
|
* Initializes the data structures related to the bundle management.
|
||||||
*
|
*
|
||||||
|
@ -108,6 +108,52 @@ class KernelTest extends \PHPUnit_Framework_TestCase
|
|||||||
$this->assertTrue($kernel->isBooted());
|
$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()
|
public function testBootKernelSeveralTimesOnlyInitializesBundlesOnce()
|
||||||
{
|
{
|
||||||
$kernel = $this->getMockBuilder('Symfony\Component\HttpKernel\Tests\Fixtures\KernelForTest')
|
$kernel = $this->getMockBuilder('Symfony\Component\HttpKernel\Tests\Fixtures\KernelForTest')
|
||||||
|
Reference in New Issue
Block a user