Skip to content

Commit 97c3f42

Browse files
committed
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.
1 parent b49998e commit 97c3f42

File tree

4 files changed

+24
-10
lines changed

4 files changed

+24
-10
lines changed

src/Symfony/Bridge/PhpUnit/Legacy/SymfonyTestsListenerTrait.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,11 @@ public function startTestSuite($suite)
120120
$this->state = 0;
121121

122122
if (!class_exists('Doctrine\Common\Annotations\AnnotationRegistry', false) && class_exists('Doctrine\Common\Annotations\AnnotationRegistry')) {
123-
AnnotationRegistry::registerLoader('class_exists');
123+
if (method_exists('Doctrine\Common\Annotations\AnnotationRegistry', 'registerUniqueLoader')) {
124+
AnnotationRegistry::registerUniqueLoader('class_exists');
125+
} else {
126+
AnnotationRegistry::registerLoader('class_exists');
127+
}
124128
}
125129

126130
if ($this->skippedFile = getenv('SYMFONY_PHPUNIT_SKIPPED_TESTS')) {

src/Symfony/Bridge/PhpUnit/bootstrap.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,11 @@
2828
setlocale(LC_ALL, 'C');
2929

3030
if (!class_exists('Doctrine\Common\Annotations\AnnotationRegistry', false) && class_exists('Doctrine\Common\Annotations\AnnotationRegistry')) {
31-
AnnotationRegistry::registerLoader('class_exists');
31+
if (method_exists('Doctrine\Common\Annotations\AnnotationRegistry', 'registerUniqueLoader')) {
32+
AnnotationRegistry::registerUniqueLoader('class_exists');
33+
} else {
34+
AnnotationRegistry::registerLoader('class_exists');
35+
}
3236
}
3337

3438
if ('disabled' !== getenv('SYMFONY_DEPRECATIONS_HELPER')) {

src/Symfony/Bundle/FrameworkBundle/DependencyInjection/FrameworkExtension.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
namespace Symfony\Bundle\FrameworkBundle\DependencyInjection;
1313

1414
use Doctrine\Common\Annotations\Reader;
15+
use Doctrine\Common\Annotations\AnnotationRegistry;
1516
use Symfony\Bridge\Monolog\Processor\DebugProcessor;
1617
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
1718
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
@@ -1087,6 +1088,11 @@ private function registerAnnotationsConfiguration(array $config, ContainerBuilde
10871088

10881089
$loader->load('annotations.xml');
10891090

1091+
if (!method_exists(AnnotationRegistry::class, 'registerUniqueLoader')) {
1092+
$container->getDefinition('annotations.dummy_registry')
1093+
->setMethodCalls(array(array('registerLoader', array('class_exists'))));
1094+
}
1095+
10901096
if ('none' !== $config['cache']) {
10911097
$cacheService = $config['cache'];
10921098

src/Symfony/Bundle/FrameworkBundle/Resources/config/annotations.xml

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,14 @@
1010
<service id="annotations.reader" class="Doctrine\Common\Annotations\AnnotationReader">
1111
<call method="addGlobalIgnoredName">
1212
<argument>required</argument>
13-
<argument type="service">
14-
<!-- dummy arg to register class_exists as annotation loader only when required -->
15-
<service class="Doctrine\Common\Annotations\AnnotationRegistry">
16-
<call method="registerLoader">
17-
<argument>class_exists</argument>
18-
</call>
19-
</service>
20-
</argument>
13+
<!-- dummy arg to register class_exists as annotation loader only when required -->
14+
<argument type="service" id="annotations.dummy_registry" />
15+
</call>
16+
</service>
17+
18+
<service id="annotations.dummy_registry" class="Doctrine\Common\Annotations\AnnotationRegistry">
19+
<call method="registerUniqueLoader">
20+
<argument>class_exists</argument>
2121
</call>
2222
</service>
2323

0 commit comments

Comments
 (0)