11
11
12
12
namespace Symfony \Bundle \MakerBundle \DependencyInjection \CompilerPass ;
13
13
14
+ use Doctrine \ORM \Mapping \Driver \AnnotationDriver ;
15
+ use Doctrine \Persistence \Mapping \Driver \AnnotationDriver as AbstractAnnotationDriver ;
14
16
use Symfony \Component \DependencyInjection \Compiler \CompilerPassInterface ;
15
17
use Symfony \Component \DependencyInjection \ContainerBuilder ;
18
+ use Symfony \Component \DependencyInjection \Definition ;
16
19
use Symfony \Component \DependencyInjection \Reference ;
17
20
18
21
class SetDoctrineAnnotatedPrefixesPass implements CompilerPassInterface
@@ -35,16 +38,35 @@ public function process(ContainerBuilder $container)
35
38
}
36
39
37
40
$ managerName = $ m [1 ];
41
+ $ methodCalls = $ metadataDriverImpl ->getMethodCalls ();
38
42
39
- foreach ($ metadataDriverImpl ->getMethodCalls () as [$ method , $ arguments ]) {
40
- if ('addDriver ' === $ method ) {
41
- $ isAnnotated = 'doctrine.orm. ' .$ managerName .'_annotation_metadata_driver ' === (string ) $ arguments [0 ];
42
- $ annotatedPrefixes [$ managerName ][] = [
43
- $ arguments [1 ],
44
- $ isAnnotated ? new Reference ($ arguments [0 ]) : null ,
45
- ];
43
+ foreach ($ methodCalls as $ i => [$ method , $ arguments ]) {
44
+ if ('addDriver ' !== $ method ) {
45
+ continue ;
46
46
}
47
+
48
+ if ($ arguments [0 ] instanceof Definition) {
49
+ $ class = $ arguments [0 ]->getClass ();
50
+ $ namespace = substr ($ class , 0 , strrpos ($ class , '\\' ));
51
+
52
+ if ('Doctrine\ORM\Mapping\Driver ' === $ namespace ? AnnotationDriver::class !== $ class : !is_subclass_of ($ class , AbstractAnnotationDriver::class)) {
53
+ continue ;
54
+ }
55
+
56
+ $ id = sprintf ('.%d_annotation_metadata_driver~%s ' , $ i , ContainerBuilder::hash ($ arguments ));
57
+ $ container ->setDefinition ($ id , $ arguments [0 ]);
58
+ $ arguments [0 ] = new Reference ($ id );
59
+ $ methodCalls [$ i ] = $ arguments ;
60
+ }
61
+
62
+ $ isAnnotated = false !== strpos ($ arguments [0 ], '_annotation_metadata_driver ' );
63
+ $ annotatedPrefixes [$ managerName ][] = [
64
+ $ arguments [1 ],
65
+ $ isAnnotated ? new Reference ($ arguments [0 ]) : null ,
66
+ ];
47
67
}
68
+
69
+ $ metadataDriverImpl ->setMethodCalls ($ methodCalls );
48
70
}
49
71
50
72
if (null !== $ annotatedPrefixes ) {
0 commit comments