Skip to content

Commit 556b38d

Browse files
Stop using deprecated ArrayCache from Doctrine
1 parent 91d7753 commit 556b38d

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

ValidatorBuilder.php

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,10 @@
1515
use Doctrine\Common\Annotations\CachedReader;
1616
use Doctrine\Common\Annotations\Reader;
1717
use Doctrine\Common\Cache\ArrayCache;
18+
use Doctrine\Common\Cache\CacheProvider;
1819
use Psr\Cache\CacheItemPoolInterface;
20+
use Symfony\Component\Cache\Adapter\ArrayAdapter;
21+
use Symfony\Component\Cache\DoctrineProvider;
1922
use Symfony\Component\Translation\TranslatorInterface as LegacyTranslatorInterface;
2023
use Symfony\Component\Validator\Context\ExecutionContextFactory;
2124
use Symfony\Component\Validator\Exception\LogicException;
@@ -197,11 +200,15 @@ public function enableAnnotationMapping(Reader $annotationReader = null)
197200
}
198201

199202
if (null === $annotationReader) {
200-
if (!class_exists(AnnotationReader::class) || !class_exists(ArrayCache::class)) {
203+
if (!class_exists(AnnotationReader::class) || !class_exists(CacheProvider::class)) {
201204
throw new LogicException('Enabling annotation based constraint mapping requires the packages doctrine/annotations and doctrine/cache to be installed.');
202205
}
203206

204-
$annotationReader = new CachedReader(new AnnotationReader(), new ArrayCache());
207+
if (class_exists(ArrayAdapter::class)) {
208+
$annotationReader = new CachedReader(new AnnotationReader(), new DoctrineProvider(new ArrayAdapter()));
209+
} else {
210+
$annotationReader = new CachedReader(new AnnotationReader(), new ArrayCache());
211+
}
205212
}
206213

207214
$this->annotationReader = $annotationReader;

0 commit comments

Comments
 (0)