@@ -95,6 +95,13 @@ public function getAlias(): string
95
95
*/
96
96
public function prepend (ContainerBuilder $ container )
97
97
{
98
+ // If no doctrine connection is configured, the DBAL connection should
99
+ // be left alone as adding any configuration setting with no connection
100
+ // will result in an invalid configuration leading to a hard failure.
101
+ if (!self ::hasDoctrineConnectionsConfigured ($ container ->getExtensionConfig ('doctrine ' ))) {
102
+ return ;
103
+ }
104
+
98
105
$ container ->prependExtensionConfig ('doctrine ' , [
99
106
'dbal ' => [
100
107
'connections ' => null ,
@@ -115,6 +122,20 @@ public function process(ContainerBuilder $container)
115
122
$ this ->assertRequiredBundlesAreEnabled ($ container );
116
123
}
117
124
125
+ /**
126
+ * @param mixed[] $configs
127
+ */
128
+ private static function hasDoctrineConnectionsConfigured (array $ configs ): bool
129
+ {
130
+ foreach ($ configs as $ config ) {
131
+ if (isset ($ config ['dbal ' ])) {
132
+ return true ;
133
+ }
134
+ }
135
+
136
+ return false ;
137
+ }
138
+
118
139
private function assertRequiredBundlesAreEnabled (ContainerBuilder $ container ): void
119
140
{
120
141
$ requiredBundles = [
@@ -254,7 +275,7 @@ private function configurePersistence(LoaderInterface $loader, ContainerBuilder
254
275
}
255
276
256
277
$ persistenceConfig = current ($ config ['persistence ' ]);
257
- $ persistenceMethod = key ($ config[ ' persistence ' ] );
278
+ $ persistenceMethod = $ this -> getPersistenceMethod ($ config );
258
279
259
280
switch ($ persistenceMethod ) {
260
281
case 'in_memory ' :
@@ -271,6 +292,16 @@ private function configurePersistence(LoaderInterface $loader, ContainerBuilder
271
292
}
272
293
}
273
294
295
+ /**
296
+ * @param mixed[] $config
297
+ */
298
+ private function getPersistenceMethod (array $ config ): ?string
299
+ {
300
+ $ persistenceMethod = key ($ config ['persistence ' ]);
301
+
302
+ return \is_string ($ persistenceMethod ) ? $ persistenceMethod : null ;
303
+ }
304
+
274
305
/**
275
306
* @param mixed[] $config
276
307
* @param mixed[] $persistenceConfig
0 commit comments