|
23 | 23 | use Doctrine\Persistence\Mapping\ClassMetadata;
|
24 | 24 | use Doctrine\Persistence\ObjectManager;
|
25 | 25 | use Gedmo\Exception\InvalidArgumentException;
|
| 26 | +use Gedmo\Exception\RuntimeException; |
26 | 27 | use Gedmo\Mapping\Driver\AttributeReader;
|
27 | 28 | use Gedmo\Mapping\Event\AdapterInterface;
|
28 | 29 | use Gedmo\ReferenceIntegrity\Mapping\Validator as ReferenceIntegrityValidator;
|
@@ -84,7 +85,10 @@ abstract class MappedEventSubscriber implements EventSubscriber
|
84 | 85 | */
|
85 | 86 | private $annotationReader;
|
86 | 87 |
|
87 |
| - private static ?PsrCachedReader $defaultAnnotationReader = null; |
| 88 | + /** |
| 89 | + * @var Reader|AttributeReader|null |
| 90 | + */ |
| 91 | + private static $defaultAnnotationReader; |
88 | 92 |
|
89 | 93 | /**
|
90 | 94 | * @var CacheItemPoolInterface|null
|
@@ -304,11 +308,19 @@ protected function setFieldValue(AdapterInterface $adapter, $object, $field, $ol
|
304 | 308 |
|
305 | 309 | /**
|
306 | 310 | * Create default annotation reader for extensions
|
| 311 | + * |
| 312 | + * @return Reader|AttributeReader |
307 | 313 | */
|
308 |
| - private function getDefaultAnnotationReader(): Reader |
| 314 | + private function getDefaultAnnotationReader() |
309 | 315 | {
|
310 | 316 | if (null === self::$defaultAnnotationReader) {
|
311 |
| - self::$defaultAnnotationReader = new PsrCachedReader(new AnnotationReader(), new ArrayAdapter()); |
| 317 | + if (class_exists(PsrCachedReader::class)) { |
| 318 | + self::$defaultAnnotationReader = new PsrCachedReader(new AnnotationReader(), new ArrayAdapter()); |
| 319 | + } elseif (\PHP_VERSION_ID >= 80000) { |
| 320 | + self::$defaultAnnotationReader = new AttributeReader(); |
| 321 | + } else { |
| 322 | + throw new RuntimeException(sprintf('Cannot create a default annotation reader in "%1$s". Ensure you are running PHP 8 to use attributes, have installed the "doctrine/annotations" package, or call "%1$s::setAnnotationReader()" with a configured reader.', self::class)); |
| 323 | + } |
312 | 324 | }
|
313 | 325 |
|
314 | 326 | return self::$defaultAnnotationReader;
|
|
0 commit comments