Skip to content

Commit 5183761

Browse files
theofidrychalasr
authored andcommitted
fix: Fix the configuration of the extension when DBAL is not configured
1 parent 06e0273 commit 5183761

File tree

1 file changed

+32
-1
lines changed

1 file changed

+32
-1
lines changed

src/DependencyInjection/LeagueOAuth2ServerExtension.php

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,13 @@ public function getAlias(): string
9595
*/
9696
public function prepend(ContainerBuilder $container)
9797
{
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+
98105
$container->prependExtensionConfig('doctrine', [
99106
'dbal' => [
100107
'connections' => null,
@@ -115,6 +122,20 @@ public function process(ContainerBuilder $container)
115122
$this->assertRequiredBundlesAreEnabled($container);
116123
}
117124

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+
118139
private function assertRequiredBundlesAreEnabled(ContainerBuilder $container): void
119140
{
120141
$requiredBundles = [
@@ -254,7 +275,7 @@ private function configurePersistence(LoaderInterface $loader, ContainerBuilder
254275
}
255276

256277
$persistenceConfig = current($config['persistence']);
257-
$persistenceMethod = key($config['persistence']);
278+
$persistenceMethod = $this->getPersistenceMethod($config);
258279

259280
switch ($persistenceMethod) {
260281
case 'in_memory':
@@ -271,6 +292,16 @@ private function configurePersistence(LoaderInterface $loader, ContainerBuilder
271292
}
272293
}
273294

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+
274305
/**
275306
* @param mixed[] $config
276307
* @param mixed[] $persistenceConfig

0 commit comments

Comments
 (0)