1616use Doctrine \Common \Persistence \Mapping \MappingException as LegacyPersistenceMappingException ;
1717use Doctrine \DBAL \Connection ;
1818use Doctrine \ORM \EntityManagerInterface ;
19+ use Doctrine \ORM \Mapping \Driver \AnnotationDriver ;
1920use Doctrine \ORM \Mapping \Driver \AttributeDriver ;
2021use Doctrine \ORM \Mapping \MappingException as ORMMappingException ;
2122use Doctrine \ORM \Mapping \NamingStrategy ;
2223use Doctrine \ORM \Tools \DisconnectedClassMetadataFactory ;
2324use Doctrine \Persistence \ManagerRegistry ;
2425use Doctrine \Persistence \Mapping \AbstractClassMetadataFactory ;
2526use Doctrine \Persistence \Mapping \ClassMetadata ;
26- use Doctrine \Persistence \Mapping \Driver \AnnotationDriver ;
27+ use Doctrine \Persistence \Mapping \Driver \AnnotationDriver as LegacyAnnotationDriver ;
2728use Doctrine \Persistence \Mapping \Driver \MappingDriver ;
2829use Doctrine \Persistence \Mapping \Driver \MappingDriverChain ;
2930use Doctrine \Persistence \Mapping \MappingException as PersistenceMappingException ;
@@ -141,7 +142,7 @@ public function doesClassUseDriver(string $className, string $driverClass): bool
141142
142143 public function isClassAnnotated (string $ className ): bool
143144 {
144- return $ this ->doesClassUseDriver ($ className , AnnotationDriver::class );
145+ return $ this ->doesClassUseDriver ($ className , $ this -> getAnnotationDriver () );
145146 }
146147
147148 public function doesClassUsesAttributes (string $ className ): bool
@@ -177,7 +178,7 @@ public function getEntitiesForAutocomplete(): array
177178 */
178179 public function getMetadata (string $ classOrNamespace = null , bool $ disconnected = false )
179180 {
180- $ classNames = (new \ReflectionClass (AnnotationDriver::class ))->getProperty ('classNames ' );
181+ $ classNames = (new \ReflectionClass ($ this -> getAnnotationDriver () ))->getProperty ('classNames ' );
181182 $ classNames ->setAccessible (true );
182183
183184 // Invalidating the cached AnnotationDriver::$classNames to find new Entity classes
@@ -186,8 +187,8 @@ public function getMetadata(string $classOrNamespace = null, bool $disconnected
186187 if (null === $ annotationDriver ) {
187188 continue ;
188189 }
189- if (class_exists (AnnotationDriver::class )) {
190- $ classNames = (new \ReflectionClass (AnnotationDriver::class ))->getProperty ('classNames ' );
190+ if (class_exists ($ this -> getAnnotationDriver () )) {
191+ $ classNames = (new \ReflectionClass ($ this -> getAnnotationDriver () ))->getProperty ('classNames ' );
191192 }
192193 if ($ annotationDriver instanceof AttributeDriver) {
193194 $ classNames = (new \ReflectionClass (AttributeDriver::class))->getProperty ('classNames ' );
@@ -229,7 +230,7 @@ public function getMetadata(string $classOrNamespace = null, bool $disconnected
229230 $ metadataDriver = $ em ->getConfiguration ()->getMetadataDriverImpl ();
230231 if ($ this ->isInstanceOf ($ metadataDriver , MappingDriverChain::class)) {
231232 foreach ($ metadataDriver ->getDrivers () as $ driver ) {
232- if ($ this ->isInstanceOf ($ driver , AnnotationDriver::class )) {
233+ if ($ this ->isInstanceOf ($ driver , $ this -> getAnnotationDriver () )) {
233234 $ classNames ->setValue ($ driver , null );
234235 }
235236 }
@@ -334,4 +335,16 @@ private function getMappingDriverForNamespace(string $namespace): ?MappingDriver
334335
335336 return $ foundDriver ;
336337 }
338+
339+ /**
340+ * Only needed in 1.39.x releases - AnnotationDriver was moved from Doctrine Persistence -> ORM.
341+ */
342+ private function getAnnotationDriver (): string
343+ {
344+ if (class_exists (AnnotationDriver::class)) {
345+ return AnnotationDriver::class;
346+ }
347+
348+ return LegacyAnnotationDriver::class;
349+ }
337350}
0 commit comments