1111
1212namespace Symfony \Bundle \MakerBundle \Doctrine ;
1313
14- use Doctrine \Common \Persistence \ManagerRegistry as LegacyManagerRegistry ;
15- use Doctrine \Common \Persistence \Mapping \ClassMetadata as LegacyClassMetadata ;
16- use Doctrine \Common \Persistence \Mapping \MappingException as LegacyPersistenceMappingException ;
1714use Doctrine \DBAL \Connection ;
1815use Doctrine \ORM \EntityManagerInterface ;
16+ use Doctrine \ORM \Mapping \Driver \AnnotationDriver ;
1917use Doctrine \ORM \Mapping \Driver \AttributeDriver ;
2018use Doctrine \ORM \Mapping \MappingException as ORMMappingException ;
2119use Doctrine \ORM \Mapping \NamingStrategy ;
2220use Doctrine \ORM \Tools \DisconnectedClassMetadataFactory ;
2321use Doctrine \Persistence \ManagerRegistry ;
2422use Doctrine \Persistence \Mapping \AbstractClassMetadataFactory ;
2523use Doctrine \Persistence \Mapping \ClassMetadata ;
26- use Doctrine \Persistence \Mapping \Driver \AnnotationDriver ;
2724use Doctrine \Persistence \Mapping \Driver \MappingDriver ;
2825use Doctrine \Persistence \Mapping \Driver \MappingDriverChain ;
2926use Doctrine \Persistence \Mapping \MappingException as PersistenceMappingException ;
@@ -44,10 +41,6 @@ final class DoctrineHelper
4441 */
4542 private $ entityNamespace ;
4643 private $ phpCompatUtil ;
47-
48- /**
49- * @var ManagerRegistry
50- */
5144 private $ registry ;
5245
5346 /**
@@ -57,10 +50,7 @@ final class DoctrineHelper
5750
5851 private $ attributeMappingSupport ;
5952
60- /**
61- * @var ManagerRegistry|LegacyManagerRegistry
62- */
63- public function __construct (string $ entityNamespace , PhpCompatUtil $ phpCompatUtil , $ registry = null , bool $ attributeMappingSupport = false , array $ annotatedPrefixes = null )
53+ public function __construct (string $ entityNamespace , PhpCompatUtil $ phpCompatUtil , ManagerRegistry $ registry = null , bool $ attributeMappingSupport = false , array $ annotatedPrefixes = null )
6454 {
6555 $ this ->entityNamespace = trim ($ entityNamespace , '\\' );
6656 $ this ->phpCompatUtil = $ phpCompatUtil ;
@@ -69,10 +59,7 @@ public function __construct(string $entityNamespace, PhpCompatUtil $phpCompatUti
6959 $ this ->mappingDriversByPrefix = $ annotatedPrefixes ;
7060 }
7161
72- /**
73- * @return LegacyManagerRegistry|ManagerRegistry
74- */
75- public function getRegistry ()
62+ public function getRegistry (): ManagerRegistry
7663 {
7764 // this should never happen: we will have checked for the
7865 // DoctrineBundle dependency before calling this
@@ -173,17 +160,21 @@ public function getEntitiesForAutocomplete(): array
173160 }
174161
175162 /**
176- * @return array|ClassMetadata|LegacyClassMetadata
163+ * @return array|ClassMetadata
177164 */
178165 public function getMetadata (string $ classOrNamespace = null , bool $ disconnected = false )
179166 {
180- $ classNames = (new \ReflectionClass (AnnotationDriver::class))->getProperty ('classNames ' );
181- $ classNames ->setAccessible (true );
182-
183167 // Invalidating the cached AnnotationDriver::$classNames to find new Entity classes
184168 foreach ($ this ->mappingDriversByPrefix ?? [] as $ managerName => $ prefixes ) {
185169 foreach ($ prefixes as [$ prefix , $ annotationDriver ]) {
186170 if (null !== $ annotationDriver ) {
171+ if ($ annotationDriver instanceof AnnotationDriver) {
172+ $ classNames = (new \ReflectionClass (AnnotationDriver::class))->getProperty ('classNames ' );
173+ } else {
174+ $ classNames = (new \ReflectionClass (AttributeDriver::class))->getProperty ('classNames ' );
175+ }
176+
177+ $ classNames ->setAccessible (true );
187178 $ classNames ->setValue ($ annotationDriver , null );
188179 }
189180 }
@@ -198,11 +189,7 @@ public function getMetadata(string $classOrNamespace = null, bool $disconnected
198189 if ($ disconnected ) {
199190 try {
200191 $ loaded = $ cmf ->getAllMetadata ();
201- } catch (ORMMappingException $ e ) {
202- $ loaded = $ this ->isInstanceOf ($ cmf , AbstractClassMetadataFactory::class) ? $ cmf ->getLoadedMetadata () : [];
203- } catch (LegacyPersistenceMappingException $ e ) {
204- $ loaded = $ this ->isInstanceOf ($ cmf , AbstractClassMetadataFactory::class) ? $ cmf ->getLoadedMetadata () : [];
205- } catch (PersistenceMappingException $ e ) {
192+ } catch (ORMMappingException |PersistenceMappingException $ e ) {
206193 $ loaded = $ this ->isInstanceOf ($ cmf , AbstractClassMetadataFactory::class) ? $ cmf ->getLoadedMetadata () : [];
207194 }
208195
@@ -221,6 +208,10 @@ public function getMetadata(string $classOrNamespace = null, bool $disconnected
221208 if ($ this ->isInstanceOf ($ driver , AnnotationDriver::class)) {
222209 $ classNames ->setValue ($ driver , null );
223210 }
211+
212+ if ($ this ->isInstanceOf ($ driver , AttributeDriver::class)) {
213+ $ classNames ->setValue ($ driver , null );
214+ }
224215 }
225216 }
226217 }
@@ -270,9 +261,7 @@ private function isInstanceOf($object, string $class): bool
270261 return false ;
271262 }
272263
273- $ legacyClass = str_replace ('Doctrine \\Persistence \\' , 'Doctrine \\Common \\Persistence \\' , $ class );
274-
275- return $ object instanceof $ class || $ object instanceof $ legacyClass ;
264+ return $ object instanceof $ class ;
276265 }
277266
278267 public function getPotentialTableName (string $ className ): string
0 commit comments