@@ -89,25 +89,8 @@ protected function loadMappingInformation(array $objectManager, ContainerBuilder
89
89
if (!$ mappingConfig ) {
90
90
continue ;
91
91
}
92
- } elseif (!$ mappingConfig ['type ' ] && \PHP_VERSION_ID < 80000 ) {
93
- $ mappingConfig ['type ' ] = 'annotation ' ;
94
92
} elseif (!$ mappingConfig ['type ' ]) {
95
- $ mappingConfig ['type ' ] = 'attribute ' ;
96
-
97
- $ glob = new GlobResource ($ mappingConfig ['dir ' ], '* ' , true );
98
- $ container ->addResource ($ glob );
99
-
100
- foreach ($ glob as $ file ) {
101
- $ content = file_get_contents ($ file );
102
-
103
- if (preg_match ('/^#\[.*Entity\b/m ' , $ content )) {
104
- break ;
105
- }
106
- if (preg_match ('/^ \* @.*Entity\b/m ' , $ content )) {
107
- $ mappingConfig ['type ' ] = 'annotation ' ;
108
- break ;
109
- }
110
- }
93
+ $ mappingConfig ['type ' ] = $ this ->detectMappingType ($ mappingConfig ['dir ' ], $ container );
111
94
}
112
95
113
96
$ this ->assertValidMappingConfiguration ($ mappingConfig , $ objectManager ['name ' ]);
@@ -278,13 +261,44 @@ protected function detectMetadataDriver(string $dir, ContainerBuilder $container
278
261
}
279
262
$ container ->fileExists ($ resource , false );
280
263
281
- return $ container ->fileExists ($ dir .'/ ' .$ this ->getMappingObjectDefaultName (), false ) ? 'annotation ' : null ;
264
+ if ($ container ->fileExists ($ dir .'/ ' .$ this ->getMappingObjectDefaultName (), false )) {
265
+ return $ this ->detectMappingType ($ dir , $ container );
266
+ }
267
+
268
+ return null ;
282
269
}
283
270
$ container ->fileExists ($ dir .'/ ' .$ configPath , false );
284
271
285
272
return $ driver ;
286
273
}
287
274
275
+ /**
276
+ * Detects what mapping type to use for the supplied directory.
277
+ *
278
+ * @return string A mapping type 'attribute' or 'annotation'
279
+ */
280
+ private function detectMappingType (string $ directory , ContainerBuilder $ container ): string
281
+ {
282
+ $ type = 'attribute ' ;
283
+
284
+ $ glob = new GlobResource ($ directory , '* ' , true );
285
+ $ container ->addResource ($ glob );
286
+
287
+ foreach ($ glob as $ file ) {
288
+ $ content = file_get_contents ($ file );
289
+
290
+ if (preg_match ('/^#\[.*Entity\b/m ' , $ content )) {
291
+ break ;
292
+ }
293
+ if (preg_match ('/^ \* @.*Entity\b/m ' , $ content )) {
294
+ $ type = 'annotation ' ;
295
+ break ;
296
+ }
297
+ }
298
+
299
+ return $ type ;
300
+ }
301
+
288
302
/**
289
303
* Loads a configured object manager metadata, query or result cache driver.
290
304
*
0 commit comments