Skip to content
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

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

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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 @@ -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,
Expand All @@ -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 = [
Expand Down Expand Up @@ -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':
Expand All @@ -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'];
Expand Down
Loading