Take advantage of AnnotationRegistry::registerUniqueLoader
This method will only add 'class_exists' as an autoloader if it has not already been added. This helps alleviate a performance issue when the same loader is added many times in tests.
This commit is contained in:
parent
b49998ebd8
commit
97c3f429eb
@ -120,7 +120,11 @@ class SymfonyTestsListenerTrait
|
||||
$this->state = 0;
|
||||
|
||||
if (!class_exists('Doctrine\Common\Annotations\AnnotationRegistry', false) && class_exists('Doctrine\Common\Annotations\AnnotationRegistry')) {
|
||||
AnnotationRegistry::registerLoader('class_exists');
|
||||
if (method_exists('Doctrine\Common\Annotations\AnnotationRegistry', 'registerUniqueLoader')) {
|
||||
AnnotationRegistry::registerUniqueLoader('class_exists');
|
||||
} else {
|
||||
AnnotationRegistry::registerLoader('class_exists');
|
||||
}
|
||||
}
|
||||
|
||||
if ($this->skippedFile = getenv('SYMFONY_PHPUNIT_SKIPPED_TESTS')) {
|
||||
|
@ -28,7 +28,11 @@ if (!defined('PHPUNIT_COMPOSER_INSTALL') && !class_exists('PHPUnit_TextUI_Comman
|
||||
setlocale(LC_ALL, 'C');
|
||||
|
||||
if (!class_exists('Doctrine\Common\Annotations\AnnotationRegistry', false) && class_exists('Doctrine\Common\Annotations\AnnotationRegistry')) {
|
||||
AnnotationRegistry::registerLoader('class_exists');
|
||||
if (method_exists('Doctrine\Common\Annotations\AnnotationRegistry', 'registerUniqueLoader')) {
|
||||
AnnotationRegistry::registerUniqueLoader('class_exists');
|
||||
} else {
|
||||
AnnotationRegistry::registerLoader('class_exists');
|
||||
}
|
||||
}
|
||||
|
||||
if ('disabled' !== getenv('SYMFONY_DEPRECATIONS_HELPER')) {
|
||||
|
@ -12,6 +12,7 @@
|
||||
namespace Symfony\Bundle\FrameworkBundle\DependencyInjection;
|
||||
|
||||
use Doctrine\Common\Annotations\Reader;
|
||||
use Doctrine\Common\Annotations\AnnotationRegistry;
|
||||
use Symfony\Bridge\Monolog\Processor\DebugProcessor;
|
||||
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
||||
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
|
||||
@ -1087,6 +1088,11 @@ class FrameworkExtension extends Extension
|
||||
|
||||
$loader->load('annotations.xml');
|
||||
|
||||
if (!method_exists(AnnotationRegistry::class, 'registerUniqueLoader')) {
|
||||
$container->getDefinition('annotations.dummy_registry')
|
||||
->setMethodCalls(array(array('registerLoader', array('class_exists'))));
|
||||
}
|
||||
|
||||
if ('none' !== $config['cache']) {
|
||||
$cacheService = $config['cache'];
|
||||
|
||||
|
@ -10,14 +10,14 @@
|
||||
<service id="annotations.reader" class="Doctrine\Common\Annotations\AnnotationReader">
|
||||
<call method="addGlobalIgnoredName">
|
||||
<argument>required</argument>
|
||||
<argument type="service">
|
||||
<!-- dummy arg to register class_exists as annotation loader only when required -->
|
||||
<service class="Doctrine\Common\Annotations\AnnotationRegistry">
|
||||
<call method="registerLoader">
|
||||
<argument>class_exists</argument>
|
||||
</call>
|
||||
</service>
|
||||
</argument>
|
||||
<!-- dummy arg to register class_exists as annotation loader only when required -->
|
||||
<argument type="service" id="annotations.dummy_registry" />
|
||||
</call>
|
||||
</service>
|
||||
|
||||
<service id="annotations.dummy_registry" class="Doctrine\Common\Annotations\AnnotationRegistry">
|
||||
<call method="registerUniqueLoader">
|
||||
<argument>class_exists</argument>
|
||||
</call>
|
||||
</service>
|
||||
|
||||
|
Reference in New Issue
Block a user