Skip to content

Commit 1586fa2

Browse files
Nyholmfabpot
authored andcommitted
[FrameworkBundle] AnnotationsCacheWarmer should support doctrine/annotations:^1.13
1 parent f664344 commit 1586fa2

File tree

2 files changed

+24
-10
lines changed

2 files changed

+24
-10
lines changed

CacheWarmer/AnnotationsCacheWarmer.php

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313

1414
use Doctrine\Common\Annotations\AnnotationException;
1515
use Doctrine\Common\Annotations\CachedReader;
16+
use Doctrine\Common\Annotations\PsrCachedReader;
1617
use Doctrine\Common\Annotations\Reader;
1718
use Symfony\Component\Cache\Adapter\ArrayAdapter;
1819
use Symfony\Component\Cache\DoctrineProvider;
@@ -52,7 +53,13 @@ protected function doWarmUp(string $cacheDir, ArrayAdapter $arrayAdapter)
5253
}
5354

5455
$annotatedClasses = include $annotatedClassPatterns;
55-
$reader = new CachedReader($this->annotationReader, new DoctrineProvider($arrayAdapter), $this->debug);
56+
57+
if (class_exists(PsrCachedReader::class)) {
58+
// doctrine/annotations:1.13 and above
59+
$reader = new PsrCachedReader($this->annotationReader, $arrayAdapter, $this->debug);
60+
} else {
61+
$reader = new CachedReader($this->annotationReader, new DoctrineProvider($arrayAdapter), $this->debug);
62+
}
5663

5764
foreach ($annotatedClasses as $class) {
5865
if (null !== $this->excludeRegexp && preg_match($this->excludeRegexp, $class)) {

Tests/CacheWarmer/AnnotationsCacheWarmerTest.php

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
use Doctrine\Common\Annotations\AnnotationReader;
66
use Doctrine\Common\Annotations\CachedReader;
7+
use Doctrine\Common\Annotations\PsrCachedReader;
78
use Doctrine\Common\Annotations\Reader;
89
use PHPUnit\Framework\MockObject\MockObject;
910
use Symfony\Bundle\FrameworkBundle\CacheWarmer\AnnotationsCacheWarmer;
@@ -42,10 +43,13 @@ public function testAnnotationsCacheWarmerWithDebugDisabled()
4243
$this->assertFileExists($cacheFile);
4344

4445
// Assert cache is valid
45-
$reader = new CachedReader(
46-
$this->getReadOnlyReader(),
47-
new DoctrineProvider(new PhpArrayAdapter($cacheFile, new NullAdapter()))
48-
);
46+
$psr6Cache = new PhpArrayAdapter($cacheFile, new NullAdapter());
47+
if (class_exists(PsrCachedReader::class)) {
48+
$reader = new PsrCachedReader($this->getReadOnlyReader(), $psr6Cache);
49+
} else {
50+
$reader = new CachedReader($this->getReadOnlyReader(), new DoctrineProvider($psr6Cache));
51+
}
52+
4953
$refClass = new \ReflectionClass($this);
5054
$reader->getClassAnnotations($refClass);
5155
$reader->getMethodAnnotations($refClass->getMethod(__FUNCTION__));
@@ -60,12 +64,15 @@ public function testAnnotationsCacheWarmerWithDebugEnabled()
6064
$warmer = new AnnotationsCacheWarmer($reader, $cacheFile, null, true);
6165
$warmer->warmUp($this->cacheDir);
6266
$this->assertFileExists($cacheFile);
67+
6368
// Assert cache is valid
64-
$reader = new CachedReader(
65-
$this->getReadOnlyReader(),
66-
new DoctrineProvider(new PhpArrayAdapter($cacheFile, new NullAdapter())),
67-
true
68-
);
69+
$psr6Cache = new PhpArrayAdapter($cacheFile, new NullAdapter());
70+
if (class_exists(PsrCachedReader::class)) {
71+
$reader = new PsrCachedReader($this->getReadOnlyReader(), $psr6Cache);
72+
} else {
73+
$reader = new CachedReader($this->getReadOnlyReader(), new DoctrineProvider($psr6Cache));
74+
}
75+
6976
$refClass = new \ReflectionClass($this);
7077
$reader->getClassAnnotations($refClass);
7178
$reader->getMethodAnnotations($refClass->getMethod(__FUNCTION__));

0 commit comments

Comments
 (0)