Merge branch '4.4' into 5.2

* 4.4:
  Stop using deprecated ArrayCache from Doctrine
  [Intl] fix Locale::getFallback() throwing exception on long $locale
This commit is contained in:
Nicolas Grekas 2021-02-18 23:42:36 +01:00
commit 11912f8c69
7 changed files with 37 additions and 12 deletions

View File

@ -12,7 +12,6 @@
namespace Symfony\Bridge\Doctrine\Test; namespace Symfony\Bridge\Doctrine\Test;
use Doctrine\Common\Annotations\AnnotationReader; use Doctrine\Common\Annotations\AnnotationReader;
use Doctrine\Common\Cache\ArrayCache;
use Doctrine\ORM\Configuration; use Doctrine\ORM\Configuration;
use Doctrine\ORM\EntityManager; use Doctrine\ORM\EntityManager;
use Doctrine\ORM\Mapping\Driver\AnnotationDriver; use Doctrine\ORM\Mapping\Driver\AnnotationDriver;
@ -62,8 +61,6 @@ class DoctrineTestHelper
$config->setProxyDir(sys_get_temp_dir()); $config->setProxyDir(sys_get_temp_dir());
$config->setProxyNamespace('SymfonyTests\Doctrine'); $config->setProxyNamespace('SymfonyTests\Doctrine');
$config->setMetadataDriverImpl(new AnnotationDriver(new AnnotationReader())); $config->setMetadataDriverImpl(new AnnotationDriver(new AnnotationReader()));
$config->setQueryCacheImpl(new ArrayCache());
$config->setMetadataCacheImpl(new ArrayCache());
return $config; return $config;
} }

View File

@ -1443,8 +1443,8 @@ class FrameworkExtension extends Extension
} }
$container $container
->getDefinition('annotations.filesystem_cache') ->getDefinition('annotations.filesystem_cache_adapter')
->replaceArgument(0, $cacheDir) ->replaceArgument(2, $cacheDir)
; ;
$cacheService = 'annotations.filesystem_cache'; $cacheService = 'annotations.filesystem_cache';

View File

@ -15,9 +15,9 @@ use Doctrine\Common\Annotations\AnnotationReader;
use Doctrine\Common\Annotations\AnnotationRegistry; use Doctrine\Common\Annotations\AnnotationRegistry;
use Doctrine\Common\Annotations\CachedReader; use Doctrine\Common\Annotations\CachedReader;
use Doctrine\Common\Annotations\Reader; use Doctrine\Common\Annotations\Reader;
use Doctrine\Common\Cache\ArrayCache;
use Doctrine\Common\Cache\FilesystemCache;
use Symfony\Bundle\FrameworkBundle\CacheWarmer\AnnotationsCacheWarmer; use Symfony\Bundle\FrameworkBundle\CacheWarmer\AnnotationsCacheWarmer;
use Symfony\Component\Cache\Adapter\ArrayAdapter;
use Symfony\Component\Cache\Adapter\FilesystemAdapter;
use Symfony\Component\Cache\Adapter\PhpArrayAdapter; use Symfony\Component\Cache\Adapter\PhpArrayAdapter;
use Symfony\Component\Cache\DoctrineProvider; use Symfony\Component\Cache\DoctrineProvider;
@ -35,15 +35,24 @@ return static function (ContainerConfigurator $container) {
->set('annotations.cached_reader', CachedReader::class) ->set('annotations.cached_reader', CachedReader::class)
->args([ ->args([
service('annotations.reader'), service('annotations.reader'),
inline_service(ArrayCache::class), inline_service(DoctrineProvider::class)->args([
inline_service(ArrayAdapter::class)
]),
abstract_arg('Debug-Flag'), abstract_arg('Debug-Flag'),
]) ])
->set('annotations.filesystem_cache', FilesystemCache::class) ->set('annotations.filesystem_cache_adapter', FilesystemAdapter::class)
->args([ ->args([
'',
0,
abstract_arg('Cache-Directory'), abstract_arg('Cache-Directory'),
]) ])
->set('annotations.filesystem_cache', DoctrineProvider::class)
->args([
service('annotations.filesystem_cache_adapter'),
])
->set('annotations.cache_warmer', AnnotationsCacheWarmer::class) ->set('annotations.cache_warmer', AnnotationsCacheWarmer::class)
->args([ ->args([
service('annotations.reader'), service('annotations.reader'),

View File

@ -928,7 +928,7 @@ abstract class FrameworkExtensionTest extends TestCase
$container->addCompilerPass(new TestAnnotationsPass()); $container->addCompilerPass(new TestAnnotationsPass());
$container->compile(); $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)); $this->assertSame('annotations.filesystem_cache', (string) $container->getDefinition('annotation_reader')->getArgument(1));
} }

View File

@ -66,7 +66,8 @@ final class Locale extends \Locale
public static function getFallback(string $locale): ?string public static function getFallback(string $locale): ?string
{ {
if (\function_exists('locale_parse')) { if (\function_exists('locale_parse')) {
$localeSubTags = locale_parse($locale); $localeSubTags = locale_parse($locale) ?? ['language' => $locale];
if (1 === \count($localeSubTags)) { if (1 === \count($localeSubTags)) {
if ('root' !== self::$defaultFallback && self::$defaultFallback === $localeSubTags['language']) { if ('root' !== self::$defaultFallback && self::$defaultFallback === $localeSubTags['language']) {
return 'root'; return 'root';

View File

@ -70,4 +70,16 @@ class LocaleTest extends TestCase
Locale::setDefaultFallback($prev); 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));
}
} }

View File

@ -16,6 +16,8 @@ use Doctrine\Common\Annotations\CachedReader;
use Doctrine\Common\Annotations\Reader; use Doctrine\Common\Annotations\Reader;
use Doctrine\Common\Cache\ArrayCache; use Doctrine\Common\Cache\ArrayCache;
use Psr\Cache\CacheItemPoolInterface; use Psr\Cache\CacheItemPoolInterface;
use Symfony\Component\Cache\Adapter\ArrayAdapter;
use Symfony\Component\Cache\DoctrineProvider;
use Symfony\Component\Validator\Context\ExecutionContextFactory; use Symfony\Component\Validator\Context\ExecutionContextFactory;
use Symfony\Component\Validator\Exception\ValidatorException; use Symfony\Component\Validator\Exception\ValidatorException;
use Symfony\Component\Validator\Mapping\Factory\LazyLoadingMetadataFactory; use Symfony\Component\Validator\Mapping\Factory\LazyLoadingMetadataFactory;
@ -266,7 +268,11 @@ class ValidatorBuilder
*/ */
public function addDefaultDoctrineAnnotationReader(): self public function addDefaultDoctrineAnnotationReader(): self
{ {
$this->annotationReader = new CachedReader(new AnnotationReader(), new ArrayCache()); if (class_exists(ArrayAdapter::class)) {
$this->annotationReader = new CachedReader(new AnnotationReader(), new DoctrineProvider(new ArrayAdapter()));
} else {
$this->annotationReader = new CachedReader(new AnnotationReader(), new ArrayCache());
}
return $this; return $this;
} }