From 97c3f429eb0e5fea990849aca022c3f30419bcc3 Mon Sep 17 00:00:00 2001 From: Jonathan Johnson Date: Sun, 10 Dec 2017 13:39:54 -0800 Subject: [PATCH] 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. --- .../PhpUnit/Legacy/SymfonyTestsListenerTrait.php | 6 +++++- src/Symfony/Bridge/PhpUnit/bootstrap.php | 6 +++++- .../DependencyInjection/FrameworkExtension.php | 6 ++++++ .../Resources/config/annotations.xml | 16 ++++++++-------- 4 files changed, 24 insertions(+), 10 deletions(-) diff --git a/src/Symfony/Bridge/PhpUnit/Legacy/SymfonyTestsListenerTrait.php b/src/Symfony/Bridge/PhpUnit/Legacy/SymfonyTestsListenerTrait.php index 655687575d..d2ddddf3f2 100644 --- a/src/Symfony/Bridge/PhpUnit/Legacy/SymfonyTestsListenerTrait.php +++ b/src/Symfony/Bridge/PhpUnit/Legacy/SymfonyTestsListenerTrait.php @@ -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')) { diff --git a/src/Symfony/Bridge/PhpUnit/bootstrap.php b/src/Symfony/Bridge/PhpUnit/bootstrap.php index a265a129e6..5de9467891 100644 --- a/src/Symfony/Bridge/PhpUnit/bootstrap.php +++ b/src/Symfony/Bridge/PhpUnit/bootstrap.php @@ -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')) { diff --git a/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/FrameworkExtension.php b/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/FrameworkExtension.php index 8b21f6c644..e4c3b08d93 100644 --- a/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/FrameworkExtension.php +++ b/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/FrameworkExtension.php @@ -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']; diff --git a/src/Symfony/Bundle/FrameworkBundle/Resources/config/annotations.xml b/src/Symfony/Bundle/FrameworkBundle/Resources/config/annotations.xml index 15bf002954..b751fe3a3d 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Resources/config/annotations.xml +++ b/src/Symfony/Bundle/FrameworkBundle/Resources/config/annotations.xml @@ -10,14 +10,14 @@ required - - - - - class_exists - - - + + + + + + + + class_exists