Skip to content

fix: Fix the configuration of the extension when DBAL is not configured #141

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 17, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 32 additions & 1 deletion src/DependencyInjection/LeagueOAuth2ServerExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,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,
Expand All @@ -115,6 +122,20 @@ public function process(ContainerBuilder $container)
$this->assertRequiredBundlesAreEnabled($container);
}

/**
* @param mixed[] $configs
*/
private static function hasDoctrineConnectionsConfigured(array $configs): bool
{
foreach ($configs as $config) {
if (isset($config['dbal'])) {
return true;
}
}

return false;
}

private function assertRequiredBundlesAreEnabled(ContainerBuilder $container): void
{
$requiredBundles = [
Expand Down Expand Up @@ -254,7 +275,7 @@ private function configurePersistence(LoaderInterface $loader, ContainerBuilder
}

$persistenceConfig = current($config['persistence']);
$persistenceMethod = key($config['persistence']);
$persistenceMethod = $this->getPersistenceMethod($config);

switch ($persistenceMethod) {
case 'in_memory':
Expand All @@ -271,6 +292,16 @@ private function configurePersistence(LoaderInterface $loader, ContainerBuilder
}
}

/**
* @param mixed[] $config
*/
private function getPersistenceMethod(array $config): ?string
{
$persistenceMethod = key($config['persistence']);

return \is_string($persistenceMethod) ? $persistenceMethod : null;
}

/**
* @param mixed[] $config
* @param mixed[] $persistenceConfig
Expand Down