33namespace DAMA \DoctrineTestBundle \DependencyInjection ;
44
55use DAMA \DoctrineTestBundle \Doctrine \Cache \Psr6StaticArrayCache ;
6- use DAMA \DoctrineTestBundle \Doctrine \DBAL \Middleware ;
76use Doctrine \Common \Cache \Cache ;
87use Doctrine \DBAL \Connection ;
98use Psr \Cache \CacheItemPoolInterface ;
109use Symfony \Component \DependencyInjection \ChildDefinition ;
1110use Symfony \Component \DependencyInjection \Compiler \CompilerPassInterface ;
1211use Symfony \Component \DependencyInjection \ContainerBuilder ;
1312use Symfony \Component \DependencyInjection \Definition ;
14- use Symfony \Component \DependencyInjection \Reference ;
1513
16- class DoctrineTestCompilerPass implements CompilerPassInterface
14+ final class ModifyDoctrineConfigCompilerPass implements CompilerPassInterface
1715{
1816 public function process (ContainerBuilder $ container ): void
1917 {
20- $ container ->register ('dama.doctrine.dbal.middleware ' , Middleware::class);
2118 $ cacheNames = [];
2219
2320 if ($ container ->getParameter ('dama. ' .Configuration::STATIC_META_CACHE )) {
@@ -31,7 +28,9 @@ public function process(ContainerBuilder $container): void
3128 /** @var array<string, mixed> $connections */
3229 $ connections = $ container ->getParameter ('doctrine.connections ' );
3330 $ connectionNames = array_keys ($ connections );
34- $ transactionalBehaviorEnabledConnections = $ this ->getTransactionEnabledConnectionNames ($ container , $ connectionNames );
31+ $ transactionalBehaviorEnabledConnections = $ container ->getParameter (
32+ AddMiddlewaresCompilerPass::TRANSACTIONAL_BEHAVIOR_ENABLED_CONNECTIONS ,
33+ );
3534 $ connectionKeys = $ this ->getConnectionKeys ($ container , $ connectionNames );
3635
3736 foreach ($ connectionNames as $ name ) {
@@ -56,10 +55,10 @@ public function process(ContainerBuilder $container): void
5655 }
5756 }
5857
59- $ container ->getParameterBag ()->remove ('dama. ' .Configuration::ENABLE_STATIC_CONNECTION );
6058 $ container ->getParameterBag ()->remove ('dama. ' .Configuration::STATIC_META_CACHE );
6159 $ container ->getParameterBag ()->remove ('dama. ' .Configuration::STATIC_QUERY_CACHE );
6260 $ container ->getParameterBag ()->remove ('dama. ' .Configuration::CONNECTION_KEYS );
61+ $ container ->getParameterBag ()->remove (AddMiddlewaresCompilerPass::TRANSACTIONAL_BEHAVIOR_ENABLED_CONNECTIONS );
6362 }
6463
6564 /**
@@ -79,24 +78,6 @@ private function modifyConnectionService(ContainerBuilder $container, $connectio
7978 0 ,
8079 $ this ->getModifiedConnectionOptions ($ connectionOptions , $ connectionKey , $ name ),
8180 );
82-
83- $ connectionConfig = $ container ->getDefinition (sprintf ('doctrine.dbal.%s_connection.configuration ' , $ name ));
84- $ methodCalls = $ connectionConfig ->getMethodCalls ();
85- $ middlewareRef = new Reference ('dama.doctrine.dbal.middleware ' );
86- $ hasMiddlewaresMethodCall = false ;
87- foreach ($ methodCalls as &$ methodCall ) {
88- if ($ methodCall [0 ] === 'setMiddlewares ' ) {
89- $ hasMiddlewaresMethodCall = true ;
90- // our middleware needs to be the first one here so we wrap the "native" driver
91- $ methodCall [1 ][0 ] = array_merge ([$ middlewareRef ], $ methodCall [1 ][0 ]);
92- }
93- }
94-
95- if (!$ hasMiddlewaresMethodCall ) {
96- $ methodCalls [] = ['setMiddlewares ' , [[$ middlewareRef ]]];
97- }
98-
99- $ connectionConfig ->setMethodCalls ($ methodCalls );
10081 }
10182
10283 /**
@@ -166,33 +147,6 @@ private function registerStaticCache(
166147 $ container ->setDefinition ($ cacheServiceId , $ cache );
167148 }
168149
169- /**
170- * @param string[] $connectionNames
171- *
172- * @return string[]
173- */
174- private function getTransactionEnabledConnectionNames (ContainerBuilder $ container , array $ connectionNames ): array
175- {
176- /** @var bool|array<string, bool> $enableStaticConnectionsConfig */
177- $ enableStaticConnectionsConfig = $ container ->getParameter ('dama. ' .Configuration::ENABLE_STATIC_CONNECTION );
178-
179- if (is_array ($ enableStaticConnectionsConfig )) {
180- $ this ->validateConnectionNames (array_keys ($ enableStaticConnectionsConfig ), $ connectionNames );
181- }
182-
183- $ enabledConnections = [];
184-
185- foreach ($ connectionNames as $ name ) {
186- if ($ enableStaticConnectionsConfig === true
187- || isset ($ enableStaticConnectionsConfig [$ name ]) && $ enableStaticConnectionsConfig [$ name ] === true
188- ) {
189- $ enabledConnections [] = $ name ;
190- }
191- }
192-
193- return $ enabledConnections ;
194- }
195-
196150 /**
197151 * @param string[] $configNames
198152 * @param string[] $existingNames
0 commit comments