Skip to content

Commit

Permalink
revert usage of connection option "dama.connection_name" (#107)
Browse files Browse the repository at this point in the history
  • Loading branch information
dmaicher authored Dec 9, 2019
1 parent 903ec9c commit 13eaeac
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,7 @@ public function process(ContainerBuilder $container): void
if ($enableStaticConnectionsConfig === true
|| isset($enableStaticConnectionsConfig[$name]) && $enableStaticConnectionsConfig[$name] === true
) {
$connectionDefinition = $container->getDefinition(sprintf('doctrine.dbal.%s_connection', $name));
$connectionOptions = $connectionDefinition->getArgument(0);
$connectionOptions['dama.connection_name'] = $name;
$connectionOptions['dama.keep_static'] = true;
$connectionDefinition->replaceArgument(0, $connectionOptions);
$this->addConnectionOptions($container, $name);
}

foreach ($cacheNames as $cacheName) {
Expand All @@ -75,4 +71,12 @@ private function validateConnectionNames(array $configNames, array $existingName
throw new \InvalidArgumentException(sprintf('Unknown doctrine dbal connection name(s): %s.', implode(', ', $unknown)));
}
}

private function addConnectionOptions(ContainerBuilder $container, string $name): void
{
$connectionDefinition = $container->getDefinition(sprintf('doctrine.dbal.%s_connection', $name));
$connectionOptions = $connectionDefinition->getArgument(0);
$connectionOptions['dama.keep_static'] = true;
$connectionDefinition->replaceArgument(0, $connectionOptions);
}
}
5 changes: 1 addition & 4 deletions src/DAMA/DoctrineTestBundle/Doctrine/DBAL/StaticDriver.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,7 @@ public function __construct(Driver $underlyingDriver, AbstractPlatform $platform
public function connect(array $params, $username = null, $password = null, array $driverOptions = []): Connection
{
if (self::$keepStaticConnections) {
if (!isset($params['dama.connection_name'])) {
throw new \InvalidArgumentException('Did not find key "dama.connection_name" inside connection params.');
}
$key = $params['dama.connection_name'];
$key = sha1(serialize($params).$username.$password);

if (!isset(self::$connections[$key])) {
self::$connections[$key] = $this->underlyingDriver->connect($params, $username, $password, $driverOptions);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,6 @@ function (ContainerBuilder $containerBuilder): void {
}

$this->assertSame([
'dama.connection_name' => 'a',
'dama.keep_static' => true,
], $containerBuilder->getDefinition('doctrine.dbal.a_connection')->getArgument(0));
},
Expand Down Expand Up @@ -103,14 +102,12 @@ function (ContainerBuilder $containerBuilder): void {
$this->assertTrue($containerBuilder->hasDefinition('dama.doctrine.dbal.connection_factory'));

$this->assertSame([
'dama.connection_name' => 'a',
'dama.keep_static' => true,
], $containerBuilder->getDefinition('doctrine.dbal.a_connection')->getArgument(0));

$this->assertSame([], $containerBuilder->getDefinition('doctrine.dbal.b_connection')->getArgument(0));

$this->assertSame([
'dama.connection_name' => 'c',
'dama.keep_static' => true,
], $containerBuilder->getDefinition('doctrine.dbal.c_connection')->getArgument(0));
},
Expand Down

0 comments on commit 13eaeac

Please sign in to comment.