[FrameworkBundle] AnnotationsCacheWarmer should support doctrine/annotations:^1.13
This commit is contained in:
parent
906b609d0e
commit
fb1cc72b18
@ -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;
|
||||||
|
|
||||||
|
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 = 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)) {
|
||||||
|
@ -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__));
|
||||||
|
Reference in New Issue
Block a user