Skip to content

Commit 2d9614b

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 6d5928b commit 2d9614b

File tree

2 files changed

+14
-8
lines changed

2 files changed

+14
-8
lines changed

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

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)