Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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 Symfony\Component\Cache\Adapter\ArrayAdapter;
use Symfony\Component\Cache\DoctrineProvider;
Expand Down Expand Up @@ -52,7 +53,13 @@ protected function doWarmUp(string $cacheDir, ArrayAdapter $arrayAdapter)
}

$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)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -42,10 +43,13 @@ public function testAnnotationsCacheWarmerWithDebugDisabled()
$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__));
Expand All @@ -60,12 +64,15 @@ 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
);
$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__));
Expand Down