From fb1cc72b184a6888c7dbf223b181363c8189936a Mon Sep 17 00:00:00 2001 From: Nyholm Date: Thu, 11 Mar 2021 08:51:28 +0100 Subject: [PATCH] [FrameworkBundle] AnnotationsCacheWarmer should support doctrine/annotations:^1.13 --- .../CacheWarmer/AnnotationsCacheWarmer.php | 9 ++++++- .../AnnotationsCacheWarmerTest.php | 25 ++++++++++++------- 2 files changed, 24 insertions(+), 10 deletions(-) diff --git a/src/Symfony/Bundle/FrameworkBundle/CacheWarmer/AnnotationsCacheWarmer.php b/src/Symfony/Bundle/FrameworkBundle/CacheWarmer/AnnotationsCacheWarmer.php index 2169eecf8a..516cbb61f3 100644 --- a/src/Symfony/Bundle/FrameworkBundle/CacheWarmer/AnnotationsCacheWarmer.php +++ b/src/Symfony/Bundle/FrameworkBundle/CacheWarmer/AnnotationsCacheWarmer.php @@ -13,6 +13,7 @@ namespace Symfony\Bundle\FrameworkBundle\CacheWarmer; use Doctrine\Common\Annotations\AnnotationException; use Doctrine\Common\Annotations\CachedReader; +use Doctrine\Common\Annotations\PsrCachedReader; use Doctrine\Common\Annotations\Reader; use Symfony\Component\Cache\Adapter\ArrayAdapter; use Symfony\Component\Cache\DoctrineProvider; @@ -52,7 +53,13 @@ class AnnotationsCacheWarmer extends AbstractPhpFileCacheWarmer } $annotatedClasses = include $annotatedClassPatterns; - $reader = new CachedReader($this->annotationReader, new DoctrineProvider($arrayAdapter), $this->debug); + + 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); + } foreach ($annotatedClasses as $class) { if (null !== $this->excludeRegexp && preg_match($this->excludeRegexp, $class)) { diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/CacheWarmer/AnnotationsCacheWarmerTest.php b/src/Symfony/Bundle/FrameworkBundle/Tests/CacheWarmer/AnnotationsCacheWarmerTest.php index 905593b280..e55720dc83 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Tests/CacheWarmer/AnnotationsCacheWarmerTest.php +++ b/src/Symfony/Bundle/FrameworkBundle/Tests/CacheWarmer/AnnotationsCacheWarmerTest.php @@ -4,6 +4,7 @@ namespace Symfony\Bundle\FrameworkBundle\Tests\CacheWarmer; 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; @@ -42,10 +43,13 @@ class AnnotationsCacheWarmerTest extends TestCase $this->assertFileExists($cacheFile); // Assert cache is valid - $reader = new CachedReader( - $this->getReadOnlyReader(), - new DoctrineProvider(new PhpArrayAdapter($cacheFile, new NullAdapter())) - ); + $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)); + } + $refClass = new \ReflectionClass($this); $reader->getClassAnnotations($refClass); $reader->getMethodAnnotations($refClass->getMethod(__FUNCTION__)); @@ -60,12 +64,15 @@ class AnnotationsCacheWarmerTest extends TestCase $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 - ); + $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)); + } + $refClass = new \ReflectionClass($this); $reader->getClassAnnotations($refClass); $reader->getMethodAnnotations($refClass->getMethod(__FUNCTION__));