[FrameworkBundle] AnnotationsCacheWarmer should support doctrine/annotations:^1.13

This commit is contained in:
Nyholm 2021-03-11 08:51:28 +01:00 committed by Fabien Potencier
parent 906b609d0e
commit fb1cc72b18
2 changed files with 24 additions and 10 deletions

View File

@ -13,6 +13,7 @@ namespace Symfony\Bundle\FrameworkBundle\CacheWarmer;
use Doctrine\Common\Annotations\AnnotationException; use Doctrine\Common\Annotations\AnnotationException;
use Doctrine\Common\Annotations\CachedReader; use Doctrine\Common\Annotations\CachedReader;
use Doctrine\Common\Annotations\PsrCachedReader;
use Doctrine\Common\Annotations\Reader; use Doctrine\Common\Annotations\Reader;
use Symfony\Component\Cache\Adapter\ArrayAdapter; use Symfony\Component\Cache\Adapter\ArrayAdapter;
use Symfony\Component\Cache\DoctrineProvider; use Symfony\Component\Cache\DoctrineProvider;
@ -52,7 +53,13 @@ class AnnotationsCacheWarmer extends AbstractPhpFileCacheWarmer
} }
$annotatedClasses = include $annotatedClassPatterns; $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) { foreach ($annotatedClasses as $class) {
if (null !== $this->excludeRegexp && preg_match($this->excludeRegexp, $class)) { if (null !== $this->excludeRegexp && preg_match($this->excludeRegexp, $class)) {

View File

@ -4,6 +4,7 @@ namespace Symfony\Bundle\FrameworkBundle\Tests\CacheWarmer;
use Doctrine\Common\Annotations\AnnotationReader; use Doctrine\Common\Annotations\AnnotationReader;
use Doctrine\Common\Annotations\CachedReader; use Doctrine\Common\Annotations\CachedReader;
use Doctrine\Common\Annotations\PsrCachedReader;
use Doctrine\Common\Annotations\Reader; use Doctrine\Common\Annotations\Reader;
use PHPUnit\Framework\MockObject\MockObject; use PHPUnit\Framework\MockObject\MockObject;
use Symfony\Bundle\FrameworkBundle\CacheWarmer\AnnotationsCacheWarmer; use Symfony\Bundle\FrameworkBundle\CacheWarmer\AnnotationsCacheWarmer;
@ -42,10 +43,13 @@ class AnnotationsCacheWarmerTest extends TestCase
$this->assertFileExists($cacheFile); $this->assertFileExists($cacheFile);
// Assert cache is valid // Assert cache is valid
$reader = new CachedReader( $psr6Cache = new PhpArrayAdapter($cacheFile, new NullAdapter());
$this->getReadOnlyReader(), if (class_exists(PsrCachedReader::class)) {
new DoctrineProvider(new PhpArrayAdapter($cacheFile, new NullAdapter())) $reader = new PsrCachedReader($this->getReadOnlyReader(), $psr6Cache);
); } else {
$reader = new CachedReader($this->getReadOnlyReader(), new DoctrineProvider($psr6Cache));
}
$refClass = new \ReflectionClass($this); $refClass = new \ReflectionClass($this);
$reader->getClassAnnotations($refClass); $reader->getClassAnnotations($refClass);
$reader->getMethodAnnotations($refClass->getMethod(__FUNCTION__)); $reader->getMethodAnnotations($refClass->getMethod(__FUNCTION__));
@ -60,12 +64,15 @@ class AnnotationsCacheWarmerTest extends TestCase
$warmer = new AnnotationsCacheWarmer($reader, $cacheFile, null, true); $warmer = new AnnotationsCacheWarmer($reader, $cacheFile, null, true);
$warmer->warmUp($this->cacheDir); $warmer->warmUp($this->cacheDir);
$this->assertFileExists($cacheFile); $this->assertFileExists($cacheFile);
// Assert cache is valid // Assert cache is valid
$reader = new CachedReader( $psr6Cache = new PhpArrayAdapter($cacheFile, new NullAdapter());
$this->getReadOnlyReader(), if (class_exists(PsrCachedReader::class)) {
new DoctrineProvider(new PhpArrayAdapter($cacheFile, new NullAdapter())), $reader = new PsrCachedReader($this->getReadOnlyReader(), $psr6Cache);
true } else {
); $reader = new CachedReader($this->getReadOnlyReader(), new DoctrineProvider($psr6Cache));
}
$refClass = new \ReflectionClass($this); $refClass = new \ReflectionClass($this);
$reader->getClassAnnotations($refClass); $reader->getClassAnnotations($refClass);
$reader->getMethodAnnotations($refClass->getMethod(__FUNCTION__)); $reader->getMethodAnnotations($refClass->getMethod(__FUNCTION__));