diff --git a/composer.json b/composer.json index 25d8974dfe..77b8c2b379 100644 --- a/composer.json +++ b/composer.json @@ -125,7 +125,7 @@ "cache/integration-tests": "dev-master", "composer/package-versions-deprecated": "^1.8", "doctrine/annotations": "^1.12", - "doctrine/cache": "~1.6", + "doctrine/cache": "^1.6|^2.0", "doctrine/collections": "~1.0", "doctrine/data-fixtures": "^1.1", "doctrine/dbal": "^2.10|^3.0", diff --git a/src/Symfony/Bridge/Doctrine/composer.json b/src/Symfony/Bridge/Doctrine/composer.json index 6e7384341c..75db8e99e7 100644 --- a/src/Symfony/Bridge/Doctrine/composer.json +++ b/src/Symfony/Bridge/Doctrine/composer.json @@ -45,7 +45,6 @@ "symfony/translation": "^4.4|^5.0", "symfony/var-dumper": "^4.4|^5.0", "doctrine/annotations": "^1.10.4", - "doctrine/cache": "~1.6", "doctrine/collections": "~1.0", "doctrine/data-fixtures": "^1.1", "doctrine/dbal": "^2.10|^3.0", diff --git a/src/Symfony/Bundle/FrameworkBundle/CacheWarmer/AnnotationsCacheWarmer.php b/src/Symfony/Bundle/FrameworkBundle/CacheWarmer/AnnotationsCacheWarmer.php index b339dee4d0..8ff2416d80 100644 --- a/src/Symfony/Bundle/FrameworkBundle/CacheWarmer/AnnotationsCacheWarmer.php +++ b/src/Symfony/Bundle/FrameworkBundle/CacheWarmer/AnnotationsCacheWarmer.php @@ -54,13 +54,10 @@ class AnnotationsCacheWarmer extends AbstractPhpFileCacheWarmer } $annotatedClasses = include $annotatedClassPatterns; - - if (class_exists(PsrCachedReader::class)) { - // doctrine/annotations:1.13 and above - $reader = new PsrCachedReader($this->annotationReader, $arrayAdapter, $this->debug); - } else { - $reader = new CachedReader($this->annotationReader, new DoctrineProvider($arrayAdapter), $this->debug); - } + $reader = class_exists(PsrCachedReader::class) + ? new PsrCachedReader($this->annotationReader, $arrayAdapter, $this->debug) + : new CachedReader($this->annotationReader, new DoctrineProvider($arrayAdapter), $this->debug) + ; foreach ($annotatedClasses as $class) { if (null !== $this->excludeRegexp && preg_match($this->excludeRegexp, $class)) { diff --git a/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Compiler/UnusedTagsPass.php b/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Compiler/UnusedTagsPass.php index 5558e3cfe8..0ca7eb17d5 100644 --- a/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Compiler/UnusedTagsPass.php +++ b/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Compiler/UnusedTagsPass.php @@ -92,6 +92,7 @@ class UnusedTagsPass implements CompilerPassInterface 'validator.auto_mapper', 'validator.constraint_validator', 'validator.initializer', + 'workflow.definition', ]; public function process(ContainerBuilder $container) diff --git a/src/Symfony/Bundle/FrameworkBundle/Resources/config/annotations.php b/src/Symfony/Bundle/FrameworkBundle/Resources/config/annotations.php index a880b75a8b..cec9f9499f 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Resources/config/annotations.php +++ b/src/Symfony/Bundle/FrameworkBundle/Resources/config/annotations.php @@ -62,14 +62,16 @@ return static function (ContainerConfigurator $container) { param('kernel.debug'), ]) + ->set('annotations.cache_adapter', PhpArrayAdapter::class) + ->factory([PhpArrayAdapter::class, 'create']) + ->args([ + param('kernel.cache_dir').'/annotations.php', + service('cache.annotations'), + ]) + ->set('annotations.cache', DoctrineProvider::class) ->args([ - inline_service(PhpArrayAdapter::class) - ->factory([PhpArrayAdapter::class, 'create']) - ->args([ - param('kernel.cache_dir').'/annotations.php', - service('cache.annotations'), - ]), + service('annotations.cache_adapter') ]) ->tag('container.hot_path') diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/CacheWarmer/AnnotationsCacheWarmerTest.php b/src/Symfony/Bundle/FrameworkBundle/Tests/CacheWarmer/AnnotationsCacheWarmerTest.php index 80bb7acc31..d5a018aa03 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Tests/CacheWarmer/AnnotationsCacheWarmerTest.php +++ b/src/Symfony/Bundle/FrameworkBundle/Tests/CacheWarmer/AnnotationsCacheWarmerTest.php @@ -44,13 +44,16 @@ class AnnotationsCacheWarmerTest extends TestCase $this->assertFileExists($cacheFile); // Assert cache is valid - $psr6Cache = new PhpArrayAdapter($cacheFile, new NullAdapter()); - if (class_exists(PsrCachedReader::class)) { - $reader = new PsrCachedReader($this->getReadOnlyReader(), $psr6Cache); - } else { - $reader = new CachedReader($this->getReadOnlyReader(), new DoctrineProvider($psr6Cache)); - } - + $reader = class_exists(PsrCachedReader::class) + ? new PsrCachedReader( + $this->getReadOnlyReader(), + new PhpArrayAdapter($cacheFile, new NullAdapter()) + ) + : new CachedReader( + $this->getReadOnlyReader(), + new DoctrineProvider(new PhpArrayAdapter($cacheFile, new NullAdapter())) + ) + ; $refClass = new \ReflectionClass($this); $reader->getClassAnnotations($refClass); $reader->getMethodAnnotations($refClass->getMethod(__FUNCTION__)); @@ -67,13 +70,19 @@ class AnnotationsCacheWarmerTest extends TestCase $this->assertFileExists($cacheFile); // Assert cache is valid - $psr6Cache = new PhpArrayAdapter($cacheFile, new NullAdapter()); - if (class_exists(PsrCachedReader::class)) { - $reader = new PsrCachedReader($this->getReadOnlyReader(), $psr6Cache); - } else { - $reader = new CachedReader($this->getReadOnlyReader(), new DoctrineProvider($psr6Cache)); - } - + $phpArrayAdapter = new PhpArrayAdapter($cacheFile, new NullAdapter()); + $reader = class_exists(PsrCachedReader::class) + ? new PsrCachedReader( + $this->getReadOnlyReader(), + $phpArrayAdapter, + true + ) + : new CachedReader( + $this->getReadOnlyReader(), + new DoctrineProvider($phpArrayAdapter), + true + ) + ; $refClass = new \ReflectionClass($this); $reader->getClassAnnotations($refClass); $reader->getMethodAnnotations($refClass->getMethod(__FUNCTION__)); diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/Functional/AutowiringTypesTest.php b/src/Symfony/Bundle/FrameworkBundle/Tests/Functional/AutowiringTypesTest.php index b122390036..39707a7e09 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Tests/Functional/AutowiringTypesTest.php +++ b/src/Symfony/Bundle/FrameworkBundle/Tests/Functional/AutowiringTypesTest.php @@ -34,7 +34,11 @@ class AutowiringTypesTest extends AbstractWebTestCase static::bootKernel(); $annotationReader = self::getContainer()->get('test.autowiring_types.autowired_services')->getAnnotationReader(); - $this->assertInstanceOf(class_exists(PsrCachedReader::class) ? PsrCachedReader::class : CachedReader::class, $annotationReader); + if (class_exists(PsrCachedReader::class)) { + $this->assertInstanceOf(PsrCachedReader::class, $annotationReader); + } else { + $this->assertInstanceOf(CachedReader::class, $annotationReader); + } } public function testEventDispatcherAutowiring() diff --git a/src/Symfony/Bundle/FrameworkBundle/composer.json b/src/Symfony/Bundle/FrameworkBundle/composer.json index c878111b2f..3417c7ce64 100644 --- a/src/Symfony/Bundle/FrameworkBundle/composer.json +++ b/src/Symfony/Bundle/FrameworkBundle/composer.json @@ -34,7 +34,7 @@ }, "require-dev": { "doctrine/annotations": "^1.10.4", - "doctrine/cache": "~1.0", + "doctrine/cache": "^1.0|^2.0", "doctrine/persistence": "^1.3|^2.0", "symfony/asset": "^5.3", "symfony/browser-kit": "^4.4|^5.0", diff --git a/src/Symfony/Bundle/TwigBundle/composer.json b/src/Symfony/Bundle/TwigBundle/composer.json index 0c1b269ce6..1d9b1cb12e 100644 --- a/src/Symfony/Bundle/TwigBundle/composer.json +++ b/src/Symfony/Bundle/TwigBundle/composer.json @@ -37,7 +37,7 @@ "symfony/framework-bundle": "^5.0", "symfony/web-link": "^4.4|^5.0", "doctrine/annotations": "^1.10.4", - "doctrine/cache": "~1.0" + "doctrine/cache": "^1.0|^2.0" }, "conflict": { "symfony/dependency-injection": "<5.3", diff --git a/src/Symfony/Component/Cache/composer.json b/src/Symfony/Component/Cache/composer.json index 9b61e71108..6917879105 100644 --- a/src/Symfony/Component/Cache/composer.json +++ b/src/Symfony/Component/Cache/composer.json @@ -32,7 +32,7 @@ }, "require-dev": { "cache/integration-tests": "dev-master", - "doctrine/cache": "^1.6", + "doctrine/cache": "^1.6|^2.0", "doctrine/dbal": "^2.10|^3.0", "predis/predis": "^1.1", "psr/simple-cache": "^1.0", diff --git a/src/Symfony/Component/Serializer/composer.json b/src/Symfony/Component/Serializer/composer.json index 6662139bcc..60a0567f92 100644 --- a/src/Symfony/Component/Serializer/composer.json +++ b/src/Symfony/Component/Serializer/composer.json @@ -23,7 +23,6 @@ }, "require-dev": { "doctrine/annotations": "^1.12", - "doctrine/cache": "~1.0", "phpdocumentor/reflection-docblock": "^3.2|^4.0|^5.0", "symfony/cache": "^4.4|^5.0", "symfony/config": "^4.4|^5.0", diff --git a/src/Symfony/Component/Validator/Tests/ValidatorBuilderTest.php b/src/Symfony/Component/Validator/Tests/ValidatorBuilderTest.php index 8da875ebc8..71057ac8f0 100644 --- a/src/Symfony/Component/Validator/Tests/ValidatorBuilderTest.php +++ b/src/Symfony/Component/Validator/Tests/ValidatorBuilderTest.php @@ -12,6 +12,7 @@ namespace Symfony\Component\Validator\Tests; use Doctrine\Common\Annotations\CachedReader; +use Doctrine\Common\Annotations\PsrCachedReader; use Doctrine\Common\Annotations\Reader; use PHPUnit\Framework\TestCase; use Psr\Cache\CacheItemPoolInterface; @@ -99,7 +100,11 @@ class ValidatorBuilderTest extends TestCase $r = new \ReflectionProperty(AnnotationLoader::class, 'reader'); $r->setAccessible(true); - $this->assertInstanceOf(CachedReader::class, $r->getValue($loaders[0])); + if (class_exists(PsrCachedReader::class)) { + $this->assertInstanceOf(PsrCachedReader::class, $r->getValue($loaders[0])); + } else { + $this->assertInstanceOf(CachedReader::class, $r->getValue($loaders[0])); + } } public function testEnableAnnotationMappingWithDefaultDoctrineAnnotationReader() @@ -114,7 +119,11 @@ class ValidatorBuilderTest extends TestCase $r = new \ReflectionProperty(AnnotationLoader::class, 'reader'); $r->setAccessible(true); - $this->assertInstanceOf(CachedReader::class, $r->getValue($loaders[0])); + if (class_exists(PsrCachedReader::class)) { + $this->assertInstanceOf(PsrCachedReader::class, $r->getValue($loaders[0])); + } else { + $this->assertInstanceOf(CachedReader::class, $r->getValue($loaders[0])); + } } /** diff --git a/src/Symfony/Component/Validator/ValidatorBuilder.php b/src/Symfony/Component/Validator/ValidatorBuilder.php index 8b363b5539..eb9e536c8b 100644 --- a/src/Symfony/Component/Validator/ValidatorBuilder.php +++ b/src/Symfony/Component/Validator/ValidatorBuilder.php @@ -13,11 +13,13 @@ namespace Symfony\Component\Validator; use Doctrine\Common\Annotations\AnnotationReader; use Doctrine\Common\Annotations\CachedReader; +use Doctrine\Common\Annotations\PsrCachedReader; use Doctrine\Common\Annotations\Reader; use Doctrine\Common\Cache\ArrayCache; +use Doctrine\Common\Cache\Psr6\DoctrineProvider; use Psr\Cache\CacheItemPoolInterface; use Symfony\Component\Cache\Adapter\ArrayAdapter; -use Symfony\Component\Cache\DoctrineProvider; +use Symfony\Component\Cache\DoctrineProvider as SymfonyDoctrineProvider; use Symfony\Component\Validator\Context\ExecutionContextFactory; use Symfony\Component\Validator\Exception\ValidatorException; use Symfony\Component\Validator\Mapping\Factory\LazyLoadingMetadataFactory; @@ -268,11 +270,7 @@ class ValidatorBuilder */ public function addDefaultDoctrineAnnotationReader(): self { - if (class_exists(ArrayAdapter::class)) { - $this->annotationReader = new CachedReader(new AnnotationReader(), new DoctrineProvider(new ArrayAdapter())); - } else { - $this->annotationReader = new CachedReader(new AnnotationReader(), new ArrayCache()); - } + $this->annotationReader = $this->createAnnotationReader(); return $this; } @@ -425,4 +423,39 @@ class ValidatorBuilder return new RecursiveValidator($contextFactory, $metadataFactory, $validatorFactory, $this->initializers); } + + private function createAnnotationReader(): Reader + { + if (!class_exists(AnnotationReader::class)) { + throw new LogicException('Enabling annotation based constraint mapping requires the packages doctrine/annotations and symfony/cache to be installed.'); + } + + // Doctrine Annotation >= 1.13, Symfony Cache + if (class_exists(PsrCachedReader::class) && class_exists(ArrayAdapter::class)) { + return new PsrCachedReader(new AnnotationReader(), new ArrayAdapter()); + } + + // Doctrine Annotations < 1.13, Doctrine Cache >= 1.11, Symfony Cache + if (class_exists(CachedReader::class) && class_exists(DoctrineProvider::class) && class_exists(ArrayAdapter::class)) { + return new CachedReader(new AnnotationReader(), DoctrineProvider::wrap(new ArrayAdapter())); + } + + // Doctrine Annotations < 1.13, Doctrine Cache < 1.11, Symfony Cache + if (class_exists(CachedReader::class) && !class_exists(DoctrineProvider::class) && class_exists(ArrayAdapter::class)) { + return new CachedReader(new AnnotationReader(), new SymfonyDoctrineProvider(new ArrayAdapter())); + } + + // Doctrine Annotations < 1.13, Doctrine Cache < 1.11 + if (class_exists(CachedReader::class) && class_exists(ArrayCache::class)) { + return new CachedReader(new AnnotationReader(), new ArrayCache()); + } + + // Doctrine Annotation >= 1.13, Doctrine Cache >= 2, no Symfony Cache + if (class_exists(PsrCachedReader::class)) { + throw new LogicException('Enabling annotation based constraint mapping requires the package symfony/cache to be installed.'); + } + + // Doctrine Annotation (<1.13 || >2), no Doctrine Cache, no Symfony Cache + throw new LogicException('Enabling annotation based constraint mapping requires the packages doctrine/annotations (>=1.13) and symfony/cache to be installed.'); + } } diff --git a/src/Symfony/Component/Validator/composer.json b/src/Symfony/Component/Validator/composer.json index d9ca4a648e..119e90b03f 100644 --- a/src/Symfony/Component/Validator/composer.json +++ b/src/Symfony/Component/Validator/composer.json @@ -41,7 +41,7 @@ "symfony/property-info": "^5.3", "symfony/translation": "^4.4|^5.0", "doctrine/annotations": "^1.10.4", - "doctrine/cache": "~1.0", + "doctrine/cache": "^1.0|^2.0", "egulias/email-validator": "^2.1.10|^3" }, "conflict": {