6
6
use Symfony \Component \DependencyInjection \ChildDefinition ;
7
7
use Symfony \Component \DependencyInjection \Compiler \CompilerPassInterface ;
8
8
use Symfony \Component \DependencyInjection \ContainerBuilder ;
9
+ use Symfony \Component \DependencyInjection \Reference ;
9
10
10
11
use function array_key_exists ;
11
12
use function array_keys ;
@@ -44,20 +45,21 @@ public function process(ContainerBuilder $container): void
44
45
}
45
46
46
47
foreach (array_keys ($ container ->getParameter ('doctrine.connections ' )) as $ name ) {
47
- $ middlewareDefs = [];
48
+ $ middlewareRefs = [];
48
49
$ i = 0 ;
49
50
foreach ($ middlewareAbstractDefs as $ id => $ abstractDef ) {
50
51
if (isset ($ middlewareConnections [$ id ]) && ! array_key_exists ($ name , $ middlewareConnections [$ id ])) {
51
52
continue ;
52
53
}
53
54
54
- $ middlewareDefs [$ id ] = [
55
- $ childDef = $ container ->setDefinition (
56
- sprintf ('%s.%s ' , $ id , $ name ),
57
- new ChildDefinition ($ id ),
58
- ),
59
- ++$ i ,
60
- ];
55
+ $ childDef = $ container ->setDefinition (
56
+ $ childId = sprintf ('%s.%s ' , $ id , $ name ),
57
+ (new ChildDefinition ($ id ))
58
+ ->setTags ($ abstractDef ->getTags ())->clearTag ('doctrine.middleware ' )
59
+ ->setAutoconfigured ($ abstractDef ->isAutoconfigured ())
60
+ ->setAutowired ($ abstractDef ->isAutowired ()),
61
+ );
62
+ $ middlewareRefs [$ id ] = [new Reference ($ childId ), ++$ i ];
61
63
62
64
if (! is_subclass_of ($ abstractDef ->getClass (), ConnectionNameAwareInterface::class)) {
63
65
continue ;
@@ -66,21 +68,21 @@ public function process(ContainerBuilder $container): void
66
68
$ childDef ->addMethodCall ('setConnectionName ' , [$ name ]);
67
69
}
68
70
69
- $ middlewareDefs = array_map (
70
- static fn ($ id , $ def ) => [
71
+ $ middlewareRefs = array_map (
72
+ static fn (string $ id , array $ ref ) => [
71
73
$ middlewareConnections [$ id ][$ name ] ?? $ middlewarePriorities [$ id ] ?? 0 ,
72
- $ def [1 ],
73
- $ def [0 ],
74
+ $ ref [1 ],
75
+ $ ref [0 ],
74
76
],
75
- array_keys ($ middlewareDefs ),
76
- array_values ($ middlewareDefs ),
77
+ array_keys ($ middlewareRefs ),
78
+ array_values ($ middlewareRefs ),
77
79
);
78
- uasort ($ middlewareDefs , static fn ($ a , $ b ) => $ b [0 ] <=> $ a [0 ] ?: $ a [1 ] <=> $ b [1 ]);
79
- $ middlewareDefs = array_map (static fn ($ value ) => $ value [2 ], $ middlewareDefs );
80
+ uasort ($ middlewareRefs , static fn (array $ a , array $ b ): int => $ b [0 ] <=> $ a [0 ] ?: $ a [1 ] <=> $ b [1 ]);
81
+ $ middlewareRefs = array_map (static fn (array $ value ): Reference => $ value [2 ], $ middlewareRefs );
80
82
81
83
$ container
82
84
->getDefinition (sprintf ('doctrine.dbal.%s_connection.configuration ' , $ name ))
83
- ->addMethodCall ('setMiddlewares ' , [$ middlewareDefs ]);
85
+ ->addMethodCall ('setMiddlewares ' , [$ middlewareRefs ]);
84
86
}
85
87
}
86
88
}
0 commit comments