From a89ced8eacd3b29e27c00609f34bf57040de09c9 Mon Sep 17 00:00:00 2001 From: bahram Date: Sat, 13 Feb 2021 22:42:31 +0330 Subject: [PATCH 1/2] [Intl] fix Locale::getFallback() throwing exception on long $locale --- src/Symfony/Component/Intl/Locale.php | 3 ++- src/Symfony/Component/Intl/Tests/LocaleTest.php | 12 ++++++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/src/Symfony/Component/Intl/Locale.php b/src/Symfony/Component/Intl/Locale.php index 0373844e76..3d07e42b13 100644 --- a/src/Symfony/Component/Intl/Locale.php +++ b/src/Symfony/Component/Intl/Locale.php @@ -68,7 +68,8 @@ final class Locale extends \Locale public static function getFallback(string $locale): ?string { if (\function_exists('locale_parse')) { - $localeSubTags = locale_parse($locale); + $localeSubTags = locale_parse($locale) ?? ['language' => $locale]; + if (1 === \count($localeSubTags)) { if ('root' !== self::$defaultFallback && self::$defaultFallback === $localeSubTags['language']) { return 'root'; diff --git a/src/Symfony/Component/Intl/Tests/LocaleTest.php b/src/Symfony/Component/Intl/Tests/LocaleTest.php index fd998612a7..fce214242a 100644 --- a/src/Symfony/Component/Intl/Tests/LocaleTest.php +++ b/src/Symfony/Component/Intl/Tests/LocaleTest.php @@ -70,4 +70,16 @@ class LocaleTest extends TestCase Locale::setDefaultFallback($prev); } + + /** + * @requires function locale_parse + */ + public function testLongLocaleFallback() + { + $locale = 'LC_TYPE=fr_FR.UTF-8;LC_NUMERIC=C;LC_TIME=fr_FR.UTF-8;LC_COLLATE=fr_FR.UTF-8;'. + 'LC_MONETARY=fr_FR.UTF-8;LC_MESSAGES=fr_FR.UTF-8;LC_PAPER=fr_FR.UTF-8;LC_NAME=fr_FR.UTF-8;'. + 'LC_ADDRESS=fr_FR.UTF-8;LC_TELEPHONE=fr_FR.UTF-8;LC_MEASUREMENT=fr_FR.UTF-8;LC_IDENTIFICATION=fr_FR.UTF-8'; + + $this->assertNull(Locale::getFallback($locale)); + } } From 15f021f825b6f6affbe6720a7ea61a99486d3c8a Mon Sep 17 00:00:00 2001 From: Nicolas Grekas Date: Thu, 18 Feb 2021 23:23:29 +0100 Subject: [PATCH 2/2] Stop using deprecated ArrayCache from Doctrine --- .../Bridge/Doctrine/Test/DoctrineTestHelper.php | 3 --- .../DependencyInjection/FrameworkExtension.php | 4 ++-- .../Resources/config/annotations.xml | 14 ++++++++++++-- .../DependencyInjection/FrameworkExtensionTest.php | 2 +- .../Component/Validator/ValidatorBuilder.php | 11 +++++++++-- 5 files changed, 24 insertions(+), 10 deletions(-) diff --git a/src/Symfony/Bridge/Doctrine/Test/DoctrineTestHelper.php b/src/Symfony/Bridge/Doctrine/Test/DoctrineTestHelper.php index 2ad16dcd4d..d3d25c17b2 100644 --- a/src/Symfony/Bridge/Doctrine/Test/DoctrineTestHelper.php +++ b/src/Symfony/Bridge/Doctrine/Test/DoctrineTestHelper.php @@ -12,7 +12,6 @@ namespace Symfony\Bridge\Doctrine\Test; use Doctrine\Common\Annotations\AnnotationReader; -use Doctrine\Common\Cache\ArrayCache; use Doctrine\ORM\Configuration; use Doctrine\ORM\EntityManager; use Doctrine\ORM\Mapping\Driver\AnnotationDriver; @@ -62,8 +61,6 @@ class DoctrineTestHelper $config->setProxyDir(sys_get_temp_dir()); $config->setProxyNamespace('SymfonyTests\Doctrine'); $config->setMetadataDriverImpl(new AnnotationDriver(new AnnotationReader())); - $config->setQueryCacheImpl(new ArrayCache()); - $config->setMetadataCacheImpl(new ArrayCache()); return $config; } diff --git a/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/FrameworkExtension.php b/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/FrameworkExtension.php index 31a3f58b0b..9d46e259fd 100644 --- a/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/FrameworkExtension.php +++ b/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/FrameworkExtension.php @@ -1447,8 +1447,8 @@ class FrameworkExtension extends Extension } $container - ->getDefinition('annotations.filesystem_cache') - ->replaceArgument(0, $cacheDir) + ->getDefinition('annotations.filesystem_cache_adapter') + ->replaceArgument(2, $cacheDir) ; $cacheService = 'annotations.filesystem_cache'; diff --git a/src/Symfony/Bundle/FrameworkBundle/Resources/config/annotations.xml b/src/Symfony/Bundle/FrameworkBundle/Resources/config/annotations.xml index 69947a35f8..2e56f1deb6 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Resources/config/annotations.xml +++ b/src/Symfony/Bundle/FrameworkBundle/Resources/config/annotations.xml @@ -24,15 +24,25 @@ - + + + + + - + + + 0 + + + + %kernel.cache_dir%/annotations.php diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/FrameworkExtensionTest.php b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/FrameworkExtensionTest.php index 7bc3edbfb8..db26edcfed 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/FrameworkExtensionTest.php +++ b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/FrameworkExtensionTest.php @@ -997,7 +997,7 @@ abstract class FrameworkExtensionTest extends TestCase $container->addCompilerPass(new TestAnnotationsPass()); $container->compile(); - $this->assertEquals($container->getParameter('kernel.cache_dir').'/annotations', $container->getDefinition('annotations.filesystem_cache')->getArgument(0)); + $this->assertEquals($container->getParameter('kernel.cache_dir').'/annotations', $container->getDefinition('annotations.filesystem_cache_adapter')->getArgument(2)); $this->assertSame('annotations.filesystem_cache', (string) $container->getDefinition('annotation_reader')->getArgument(1)); } diff --git a/src/Symfony/Component/Validator/ValidatorBuilder.php b/src/Symfony/Component/Validator/ValidatorBuilder.php index 17e4fbd024..87267a45ac 100644 --- a/src/Symfony/Component/Validator/ValidatorBuilder.php +++ b/src/Symfony/Component/Validator/ValidatorBuilder.php @@ -15,7 +15,10 @@ use Doctrine\Common\Annotations\AnnotationReader; use Doctrine\Common\Annotations\CachedReader; use Doctrine\Common\Annotations\Reader; use Doctrine\Common\Cache\ArrayCache; +use Doctrine\Common\Cache\CacheProvider; use Psr\Cache\CacheItemPoolInterface; +use Symfony\Component\Cache\Adapter\ArrayAdapter; +use Symfony\Component\Cache\DoctrineProvider; use Symfony\Component\Translation\TranslatorInterface as LegacyTranslatorInterface; use Symfony\Component\Validator\Context\ExecutionContextFactory; use Symfony\Component\Validator\Exception\LogicException; @@ -197,11 +200,15 @@ class ValidatorBuilder implements ValidatorBuilderInterface } if (null === $annotationReader) { - if (!class_exists(AnnotationReader::class) || !class_exists(ArrayCache::class)) { + if (!class_exists(AnnotationReader::class) || !class_exists(CacheProvider::class)) { throw new LogicException('Enabling annotation based constraint mapping requires the packages doctrine/annotations and doctrine/cache to be installed.'); } - $annotationReader = new CachedReader(new AnnotationReader(), new ArrayCache()); + if (class_exists(ArrayAdapter::class)) { + $annotationReader = new CachedReader(new AnnotationReader(), new DoctrineProvider(new ArrayAdapter())); + } else { + $annotationReader = new CachedReader(new AnnotationReader(), new ArrayCache()); + } } $this->annotationReader = $annotationReader;