diff --git a/composer.json b/composer.json
index 737f767885da5..39a35f30f1087 100644
--- a/composer.json
+++ b/composer.json
@@ -119,7 +119,7 @@
"cache/integration-tests": "dev-master",
"composer/package-versions-deprecated": "^1.8",
"doctrine/annotations": "^1.10.4",
- "doctrine/cache": "~1.6",
+ "doctrine/cache": "^1.6|^2.0",
"doctrine/collections": "~1.0",
"doctrine/data-fixtures": "^1.1",
"doctrine/dbal": "^2.6|^3.0",
diff --git a/src/Symfony/Bridge/Doctrine/composer.json b/src/Symfony/Bridge/Doctrine/composer.json
index 68fbcef8c7b53..17a83e7d12e7c 100644
--- a/src/Symfony/Bridge/Doctrine/composer.json
+++ b/src/Symfony/Bridge/Doctrine/composer.json
@@ -40,7 +40,6 @@
"symfony/var-dumper": "^3.4|^4.0|^5.0",
"symfony/translation": "^3.4|^4.0|^5.0",
"doctrine/annotations": "^1.10.4",
- "doctrine/cache": "~1.6",
"doctrine/collections": "~1.0",
"doctrine/data-fixtures": "^1.1",
"doctrine/dbal": "^2.6|^3.0",
diff --git a/src/Symfony/Bundle/FrameworkBundle/CacheWarmer/AnnotationsCacheWarmer.php b/src/Symfony/Bundle/FrameworkBundle/CacheWarmer/AnnotationsCacheWarmer.php
index 7dd50aa31a735..8ed3f618f902a 100644
--- a/src/Symfony/Bundle/FrameworkBundle/CacheWarmer/AnnotationsCacheWarmer.php
+++ b/src/Symfony/Bundle/FrameworkBundle/CacheWarmer/AnnotationsCacheWarmer.php
@@ -13,6 +13,7 @@
use Doctrine\Common\Annotations\AnnotationException;
use Doctrine\Common\Annotations\CachedReader;
+use Doctrine\Common\Annotations\PsrCachedReader;
use Doctrine\Common\Annotations\Reader;
use Psr\Cache\CacheItemPoolInterface;
use Symfony\Component\Cache\Adapter\ArrayAdapter;
@@ -61,7 +62,10 @@ protected function doWarmUp($cacheDir, ArrayAdapter $arrayAdapter)
}
$annotatedClasses = include $annotatedClassPatterns;
- $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/FrameworkExtension.php b/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/FrameworkExtension.php
index b6fad07ad98b3..1e0ee70ccbaaf 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\AnnotationRegistry;
+use Doctrine\Common\Annotations\PsrCachedReader;
use Doctrine\Common\Annotations\Reader;
use Http\Client\HttpClient;
use Psr\Cache\CacheItemPoolInterface;
@@ -1423,14 +1424,20 @@ private function registerAnnotationsConfiguration(array $config, ContainerBuilde
}
if ('none' !== $config['cache']) {
- if (!class_exists(\Doctrine\Common\Cache\CacheProvider::class)) {
+ if (class_exists(PsrCachedReader::class)) {
+ $container
+ ->getDefinition('annotations.cached_reader')
+ ->setClass(PsrCachedReader::class)
+ ->replaceArgument(1, new Definition(ArrayAdapter::class))
+ ;
+ } elseif (!class_exists(\Doctrine\Common\Cache\CacheProvider::class)) {
throw new LogicException('Annotations cannot be enabled as the Doctrine Cache library is not installed.');
}
$cacheService = $config['cache'];
if ('php_array' === $config['cache']) {
- $cacheService = 'annotations.cache';
+ $cacheService = class_exists(PsrCachedReader::class) ? 'annotations.cache_adapter' : 'annotations.cache';
// Enable warmer only if PHP array is used for cache
$definition = $container->findDefinition('annotations.cache_warmer');
@@ -1447,7 +1454,7 @@ private function registerAnnotationsConfiguration(array $config, ContainerBuilde
->replaceArgument(2, $cacheDir)
;
- $cacheService = 'annotations.filesystem_cache';
+ $cacheService = class_exists(PsrCachedReader::class) ? 'annotations.filesystem_cache_adapter' : 'annotations.filesystem_cache';
}
$container
diff --git a/src/Symfony/Bundle/FrameworkBundle/Resources/config/annotations.xml b/src/Symfony/Bundle/FrameworkBundle/Resources/config/annotations.xml
index 2e56f1deb62f3..4420dfbf00db1 100644
--- a/src/Symfony/Bundle/FrameworkBundle/Resources/config/annotations.xml
+++ b/src/Symfony/Bundle/FrameworkBundle/Resources/config/annotations.xml
@@ -50,14 +50,15 @@
%kernel.debug%
+
+
+ %kernel.cache_dir%/annotations.php
+
+
+
+
-
-
-
- %kernel.cache_dir%/annotations.php
-
-
-
+
diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/CacheWarmer/AnnotationsCacheWarmerTest.php b/src/Symfony/Bundle/FrameworkBundle/Tests/CacheWarmer/AnnotationsCacheWarmerTest.php
index 9b257a2bf1b88..9e353ad7bbca2 100644
--- a/src/Symfony/Bundle/FrameworkBundle/Tests/CacheWarmer/AnnotationsCacheWarmerTest.php
+++ b/src/Symfony/Bundle/FrameworkBundle/Tests/CacheWarmer/AnnotationsCacheWarmerTest.php
@@ -4,6 +4,7 @@
use Doctrine\Common\Annotations\AnnotationReader;
use Doctrine\Common\Annotations\CachedReader;
+use Doctrine\Common\Annotations\PsrCachedReader;
use Doctrine\Common\Annotations\Reader;
use PHPUnit\Framework\MockObject\MockObject;
use Symfony\Bundle\FrameworkBundle\CacheWarmer\AnnotationsCacheWarmer;
@@ -43,10 +44,16 @@ public function testAnnotationsCacheWarmerWithDebugDisabled()
$this->assertFileExists($cacheFile);
// Assert cache is valid
- $reader = new CachedReader(
- $this->getReadOnlyReader(),
- new DoctrineProvider(new PhpArrayAdapter($cacheFile, new NullAdapter()))
- );
+ $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__));
@@ -61,12 +68,21 @@ public function testAnnotationsCacheWarmerWithDebugEnabled()
$warmer = new AnnotationsCacheWarmer($reader, $cacheFile, null, true);
$warmer->warmUp($this->cacheDir);
$this->assertFileExists($cacheFile);
+
// Assert cache is valid
- $reader = new CachedReader(
- $this->getReadOnlyReader(),
- new DoctrineProvider(new PhpArrayAdapter($cacheFile, new NullAdapter())),
- true
- );
+ $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/DependencyInjection/FrameworkExtensionTest.php b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/FrameworkExtensionTest.php
index 35977510bb684..396a04e8b4bf9 100644
--- a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/FrameworkExtensionTest.php
+++ b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/FrameworkExtensionTest.php
@@ -12,6 +12,7 @@
namespace Symfony\Bundle\FrameworkBundle\Tests\DependencyInjection;
use Doctrine\Common\Annotations\Annotation;
+use Doctrine\Common\Annotations\PsrCachedReader;
use Psr\Log\LoggerAwareInterface;
use Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler\AddAnnotationsCachedReaderPass;
use Symfony\Bundle\FrameworkBundle\DependencyInjection\FrameworkExtension;
@@ -999,7 +1000,11 @@ public function testAnnotations()
$container->compile();
$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));
+ if (class_exists(PsrCachedReader::class)) {
+ $this->assertSame('annotations.filesystem_cache_adapter', (string) $container->getDefinition('annotation_reader')->getArgument(1));
+ } else {
+ $this->assertSame('annotations.filesystem_cache', (string) $container->getDefinition('annotation_reader')->getArgument(1));
+ }
}
public function testFileLinkFormat()
diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/Functional/AutowiringTypesTest.php b/src/Symfony/Bundle/FrameworkBundle/Tests/Functional/AutowiringTypesTest.php
index f6149ea874f8d..fdeaf98fb0293 100644
--- a/src/Symfony/Bundle/FrameworkBundle/Tests/Functional/AutowiringTypesTest.php
+++ b/src/Symfony/Bundle/FrameworkBundle/Tests/Functional/AutowiringTypesTest.php
@@ -13,6 +13,7 @@
use Doctrine\Common\Annotations\AnnotationReader;
use Doctrine\Common\Annotations\CachedReader;
+use Doctrine\Common\Annotations\PsrCachedReader;
use Symfony\Bundle\FrameworkBundle\Templating\EngineInterface as FrameworkBundleEngineInterface;
use Symfony\Component\Cache\Adapter\FilesystemAdapter;
use Symfony\Component\EventDispatcher\EventDispatcher;
@@ -35,7 +36,11 @@ public function testCachedAnnotationReaderAutowiring()
static::bootKernel();
$annotationReader = static::$container->get('test.autowiring_types.autowired_services')->getAnnotationReader();
- $this->assertInstanceOf(CachedReader::class, $annotationReader);
+ if (class_exists(PsrCachedReader::class)) {
+ $this->assertInstanceOf(PsrCachedReader::class, $annotationReader);
+ } else {
+ $this->assertInstanceOf(CachedReader::class, $annotationReader);
+ }
}
/**
diff --git a/src/Symfony/Bundle/FrameworkBundle/composer.json b/src/Symfony/Bundle/FrameworkBundle/composer.json
index f26298324f1e4..efa69d2be340c 100644
--- a/src/Symfony/Bundle/FrameworkBundle/composer.json
+++ b/src/Symfony/Bundle/FrameworkBundle/composer.json
@@ -19,7 +19,7 @@
"php": ">=7.1.3",
"ext-xml": "*",
"symfony/cache": "^4.4|^5.0",
- "symfony/config": "^4.3.4|^5.0",
+ "symfony/config": "^4.4.11|~5.0.11|^5.1.3",
"symfony/dependency-injection": "^4.4.1|^5.0.1",
"symfony/error-handler": "^4.4.1|^5.0.1",
"symfony/http-foundation": "^4.4|^5.0",
@@ -31,7 +31,7 @@
},
"require-dev": {
"doctrine/annotations": "^1.10.4",
- "doctrine/cache": "~1.0",
+ "doctrine/cache": "^1.0|^2.0",
"doctrine/persistence": "^1.3|^2.0",
"paragonie/sodium_compat": "^1.8",
"symfony/asset": "^3.4|^4.0|^5.0",
diff --git a/src/Symfony/Bundle/TwigBundle/composer.json b/src/Symfony/Bundle/TwigBundle/composer.json
index 57cf455107bb0..0178473326827 100644
--- a/src/Symfony/Bundle/TwigBundle/composer.json
+++ b/src/Symfony/Bundle/TwigBundle/composer.json
@@ -37,7 +37,7 @@
"symfony/framework-bundle": "^4.4|^5.0",
"symfony/web-link": "^3.4|^4.0|^5.0",
"doctrine/annotations": "^1.10.4",
- "doctrine/cache": "~1.0"
+ "doctrine/cache": "^1.0|^2.0"
},
"conflict": {
"symfony/dependency-injection": "<4.1",
diff --git a/src/Symfony/Component/Cache/composer.json b/src/Symfony/Component/Cache/composer.json
index 87a26071a6634..209d758eedaca 100644
--- a/src/Symfony/Component/Cache/composer.json
+++ b/src/Symfony/Component/Cache/composer.json
@@ -30,7 +30,7 @@
},
"require-dev": {
"cache/integration-tests": "dev-master",
- "doctrine/cache": "^1.6",
+ "doctrine/cache": "^1.6|^2.0",
"doctrine/dbal": "^2.6|^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 2cf3920ac8203..075896e4785ca 100644
--- a/src/Symfony/Component/Serializer/composer.json
+++ b/src/Symfony/Component/Serializer/composer.json
@@ -21,7 +21,6 @@
},
"require-dev": {
"doctrine/annotations": "^1.10.4",
- "doctrine/cache": "~1.0",
"phpdocumentor/reflection-docblock": "^3.2|^4.0|^5.0",
"symfony/cache": "^3.4|^4.0|^5.0",
"symfony/config": "^3.4|^4.0|^5.0",
@@ -49,8 +48,7 @@
"symfony/config": "For using the XML mapping loader.",
"symfony/property-access": "For using the ObjectNormalizer.",
"symfony/http-foundation": "For using a MIME type guesser within the DataUriNormalizer.",
- "doctrine/annotations": "For using the annotation mapping. You will also need doctrine/cache.",
- "doctrine/cache": "For using the default cached annotation reader and metadata cache."
+ "doctrine/annotations": "For using the annotation mapping."
},
"autoload": {
"psr-4": { "Symfony\\Component\\Serializer\\": "" },
diff --git a/src/Symfony/Component/Validator/Tests/Mapping/Cache/DoctrineCacheTest.php b/src/Symfony/Component/Validator/Tests/Mapping/Cache/DoctrineCacheTest.php
index e73b0d99668ec..ec9b0920f6d29 100644
--- a/src/Symfony/Component/Validator/Tests/Mapping/Cache/DoctrineCacheTest.php
+++ b/src/Symfony/Component/Validator/Tests/Mapping/Cache/DoctrineCacheTest.php
@@ -12,6 +12,8 @@
namespace Symfony\Component\Validator\Tests\Mapping\Cache;
use Doctrine\Common\Cache\ArrayCache;
+use Doctrine\Common\Cache\Psr6\DoctrineProvider;
+use Symfony\Component\Cache\Adapter\ArrayAdapter;
use Symfony\Component\Validator\Mapping\Cache\DoctrineCache;
/**
@@ -21,6 +23,9 @@ class DoctrineCacheTest extends AbstractCacheTest
{
protected function setUp(): void
{
- $this->cache = new DoctrineCache(new ArrayCache());
+ $this->cache = class_exists(DoctrineProvider::class)
+ ? new DoctrineCache(DoctrineProvider::wrap(new ArrayAdapter()))
+ : new DoctrineCache(new ArrayCache())
+ ;
}
}
diff --git a/src/Symfony/Component/Validator/ValidatorBuilder.php b/src/Symfony/Component/Validator/ValidatorBuilder.php
index 292a55c9859c5..e3fe807ff9835 100644
--- a/src/Symfony/Component/Validator/ValidatorBuilder.php
+++ b/src/Symfony/Component/Validator/ValidatorBuilder.php
@@ -13,12 +13,13 @@
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\CacheProvider;
+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\Translation\TranslatorInterface as LegacyTranslatorInterface;
use Symfony\Component\Validator\Context\ExecutionContextFactory;
use Symfony\Component\Validator\Exception\LogicException;
@@ -199,19 +200,7 @@ public function enableAnnotationMapping(Reader $annotationReader = null)
throw new ValidatorException('You cannot enable annotation mapping after setting a custom metadata factory. Configure your metadata factory instead.');
}
- if (null === $annotationReader) {
- 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.');
- }
-
- 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;
+ $this->annotationReader = $annotationReader ?? $this->createAnnotationReader();
return $this;
}
@@ -386,4 +375,39 @@ public function getValidator()
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 c9cbe689ce0fc..e32a72bcf95ac 100644
--- a/src/Symfony/Component/Validator/composer.json
+++ b/src/Symfony/Component/Validator/composer.json
@@ -36,7 +36,7 @@
"symfony/property-info": "^3.4|^4.0|^5.0",
"symfony/translation": "^4.2",
"doctrine/annotations": "^1.10.4",
- "doctrine/cache": "~1.0",
+ "doctrine/cache": "^1.0|^2.0",
"egulias/email-validator": "^2.1.10|^3"
},
"conflict": {