diff --git a/src/DependencyInjection/LeagueOAuth2ServerExtension.php b/src/DependencyInjection/LeagueOAuth2ServerExtension.php index 81922ad0..d7f30bca 100644 --- a/src/DependencyInjection/LeagueOAuth2ServerExtension.php +++ b/src/DependencyInjection/LeagueOAuth2ServerExtension.php @@ -81,6 +81,13 @@ public function getAlias(): string */ public function prepend(ContainerBuilder $container) { + // If no doctrine connection is configured, the DBAL connection should + // be left alone as adding any configuration setting with no connection + // will result in an invalid configuration leading to a hard failure. + if (!self::hasDoctrineConnectionsConfigured($container->getExtensionConfig('doctrine'))) { + return; + } + $container->prependExtensionConfig('doctrine', [ 'dbal' => [ 'connections' => null, @@ -101,6 +108,23 @@ public function process(ContainerBuilder $container) $this->assertRequiredBundlesAreEnabled($container); } + private static function hasDoctrineConnectionsConfigured(array $configs): bool + { + foreach ($configs as $config) { + if (!isset($config['dbal'])) { + continue; + } + + if (isset($config['dbal']['connections']) + && \count($config['dbal']['connections']) > 0 + ) { + return true; + } + } + + return false; + } + private function assertRequiredBundlesAreEnabled(ContainerBuilder $container): void { $requiredBundles = [ @@ -218,7 +242,7 @@ private function configurePersistence(LoaderInterface $loader, ContainerBuilder } $persistenceConfig = current($config['persistence']); - $persistenceMethod = key($config['persistence']); + $persistenceMethod = $this->getPersistenceMethod($config); switch ($persistenceMethod) { case 'in_memory': @@ -232,6 +256,13 @@ private function configurePersistence(LoaderInterface $loader, ContainerBuilder } } + private function getPersistenceMethod(array $config): ?string + { + $persistenceMethod = key($config['persistence']); + + return \is_string($persistenceMethod) ? $persistenceMethod : null; + } + private function configureDoctrinePersistence(ContainerBuilder $container, array $config, array $persistenceConfig): void { $entityManagerName = $persistenceConfig['entity_manager'];