From b55afb9a85ca1442eebbcfba3fdfa29fbcbbcaa7 Mon Sep 17 00:00:00 2001 From: Alexis Lefebvre Date: Sun, 8 Jan 2023 02:19:40 +0100 Subject: [PATCH 1/3] add compatibility layer for doctrine/annotations --- .../FrameworkExtension.php | 9 ------ .../Resources/config/annotations.php | 30 +++++++++++++++---- 2 files changed, 25 insertions(+), 14 deletions(-) diff --git a/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/FrameworkExtension.php b/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/FrameworkExtension.php index b69254687c6d4..b11830c225891 100644 --- a/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/FrameworkExtension.php +++ b/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/FrameworkExtension.php @@ -1631,15 +1631,6 @@ private function registerAnnotationsConfiguration(array $config, ContainerBuilde $loader->load('annotations.php'); - if (!method_exists(AnnotationRegistry::class, 'registerUniqueLoader')) { - if (method_exists(AnnotationRegistry::class, 'registerLoader')) { - $container->getDefinition('annotations.dummy_registry') - ->setMethodCalls([['registerLoader', ['class_exists']]]); - } else { - $container->removeDefinition('annotations.dummy_registry'); - } - } - if ('none' === $config['cache']) { $container->removeDefinition('annotations.cached_reader'); diff --git a/src/Symfony/Bundle/FrameworkBundle/Resources/config/annotations.php b/src/Symfony/Bundle/FrameworkBundle/Resources/config/annotations.php index 8bb408e2aba65..3a4ac708e2f05 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Resources/config/annotations.php +++ b/src/Symfony/Bundle/FrameworkBundle/Resources/config/annotations.php @@ -22,16 +22,36 @@ use Symfony\Component\Cache\Adapter\PhpArrayAdapter; return static function (ContainerConfigurator $container) { - $container->services() - ->set('annotations.reader', AnnotationReader::class) + // compatibility layer to support doctrine/annotations ^1.0 and ^2.0 + // registerLoader only exists in doctrine/annotations ^1.0 + if (method_exists(AnnotationRegistry::class, 'registerLoader')) { + // registerUniqueLoader only exists in doctrine/annotations ^1.6 + if (method_exists(AnnotationRegistry::class, 'registerUniqueLoader')) { + $container->services() + ->set('annotations.dummy_registry', AnnotationRegistry::class) + ->call('registerUniqueLoader', ['class_exists']); + } else { + $container->services() + ->set('annotations.dummy_registry', AnnotationRegistry::class) + ->call('registerLoader', ['class_exists']); + } + + $container->services() + ->set('annotations.reader', AnnotationReader::class) ->call('addGlobalIgnoredName', [ 'required', service('annotations.dummy_registry')->ignoreOnInvalid(), // dummy arg to register class_exists as annotation loader only when required ]) + ; + } + // for doctrine/annotations v2 + else { + $container->services() + ->set('annotations.reader', AnnotationReader::class) + ->call('addGlobalIgnoredName', ['required']); + } - ->set('annotations.dummy_registry', AnnotationRegistry::class) - ->call('registerUniqueLoader', ['class_exists']) - + $container->services() ->set('annotations.cached_reader', PsrCachedReader::class) ->args([ service('annotations.reader'), From 6065255319c9608cf127d42c02f5e150d04541a0 Mon Sep 17 00:00:00 2001 From: Alexis Lefebvre Date: Sun, 8 Jan 2023 02:39:14 +0100 Subject: [PATCH 2/3] don't perform checks for doctrine/annotations < 1.13.1 --- .../Resources/config/annotations.php | 22 +++++++------------ 1 file changed, 8 insertions(+), 14 deletions(-) diff --git a/src/Symfony/Bundle/FrameworkBundle/Resources/config/annotations.php b/src/Symfony/Bundle/FrameworkBundle/Resources/config/annotations.php index 3a4ac708e2f05..37ff8c58b1418 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Resources/config/annotations.php +++ b/src/Symfony/Bundle/FrameworkBundle/Resources/config/annotations.php @@ -22,19 +22,13 @@ use Symfony\Component\Cache\Adapter\PhpArrayAdapter; return static function (ContainerConfigurator $container) { - // compatibility layer to support doctrine/annotations ^1.0 and ^2.0 - // registerLoader only exists in doctrine/annotations ^1.0 - if (method_exists(AnnotationRegistry::class, 'registerLoader')) { - // registerUniqueLoader only exists in doctrine/annotations ^1.6 - if (method_exists(AnnotationRegistry::class, 'registerUniqueLoader')) { - $container->services() - ->set('annotations.dummy_registry', AnnotationRegistry::class) - ->call('registerUniqueLoader', ['class_exists']); - } else { - $container->services() - ->set('annotations.dummy_registry', AnnotationRegistry::class) - ->call('registerLoader', ['class_exists']); - } + // compatibility layer to support doctrine/annotations ^1.13 and ^2.0 + // registerUniqueLoader only exists in doctrine/annotations ^1.13 + // (it was added in 1.6 but a conflict forbid versions lower than 1.13.1) + if (method_exists(AnnotationRegistry::class, 'registerUniqueLoader')) { + $container->services() + ->set('annotations.dummy_registry', AnnotationRegistry::class) + ->call('registerUniqueLoader', ['class_exists']); $container->services() ->set('annotations.reader', AnnotationReader::class) @@ -44,7 +38,7 @@ ]) ; } - // for doctrine/annotations v2 + // with doctrine/annotations v2, there's no need for annotations.dummy_registry else { $container->services() ->set('annotations.reader', AnnotationReader::class) From 539f5abd48a6f97d402065ccff87d2ea816a41ea Mon Sep 17 00:00:00 2001 From: Alexis Lefebvre Date: Sun, 8 Jan 2023 02:53:36 +0100 Subject: [PATCH 3/3] fabbot --- .../FrameworkExtension.php | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/FrameworkExtension.php b/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/FrameworkExtension.php index b11830c225891..28f47d3ad93b9 100644 --- a/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/FrameworkExtension.php +++ b/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/FrameworkExtension.php @@ -12,7 +12,6 @@ namespace Symfony\Bundle\FrameworkBundle\DependencyInjection; use Composer\InstalledVersions; -use Doctrine\Common\Annotations\AnnotationRegistry; use Doctrine\Common\Annotations\Reader; use Http\Client\HttpClient; use phpDocumentor\Reflection\DocBlockFactoryInterface; @@ -2678,12 +2677,18 @@ private function resolveTrustedHeaders(array $headers): int foreach ($headers as $h) { switch ($h) { - case 'forwarded': $trustedHeaders |= Request::HEADER_FORWARDED; break; - case 'x-forwarded-for': $trustedHeaders |= Request::HEADER_X_FORWARDED_FOR; break; - case 'x-forwarded-host': $trustedHeaders |= Request::HEADER_X_FORWARDED_HOST; break; - case 'x-forwarded-proto': $trustedHeaders |= Request::HEADER_X_FORWARDED_PROTO; break; - case 'x-forwarded-port': $trustedHeaders |= Request::HEADER_X_FORWARDED_PORT; break; - case 'x-forwarded-prefix': $trustedHeaders |= Request::HEADER_X_FORWARDED_PREFIX; break; + case 'forwarded': $trustedHeaders |= Request::HEADER_FORWARDED; + break; + case 'x-forwarded-for': $trustedHeaders |= Request::HEADER_X_FORWARDED_FOR; + break; + case 'x-forwarded-host': $trustedHeaders |= Request::HEADER_X_FORWARDED_HOST; + break; + case 'x-forwarded-proto': $trustedHeaders |= Request::HEADER_X_FORWARDED_PROTO; + break; + case 'x-forwarded-port': $trustedHeaders |= Request::HEADER_X_FORWARDED_PORT; + break; + case 'x-forwarded-prefix': $trustedHeaders |= Request::HEADER_X_FORWARDED_PREFIX; + break; } }