Skip to content

Commit

Permalink
Added the ability to extend StaticDriver for greater flexibility.
Browse files Browse the repository at this point in the history
  • Loading branch information
prohalexey committed Apr 25, 2024
1 parent 92c9a38 commit a0e788e
Showing 1 changed file with 21 additions and 6 deletions.
27 changes: 21 additions & 6 deletions src/DAMA/DoctrineTestBundle/Doctrine/DBAL/StaticDriver.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,15 @@ public function connect(array $params): Connection
return parent::connect($params);
}

$key = sha1(json_encode($params));
$key = $this->getConnectionHash($params);

if (!isset(self::$connections[$key])) {
self::$connections[$key] = parent::connect($params);
self::$connections[$key]->beginTransaction();
$connection = $this->getConnection($key);
if (null === $connection) {
$connection = parent::connect($params);
$this->addConnection($key, $connection);
$connection->beginTransaction();
}

$connection = self::$connections[$key];

$platform = $this->getPlatform($connection, $params);

if (!$platform->supportsSavepoints()) {
Expand Down Expand Up @@ -77,6 +77,21 @@ public static function commit(): void
}
}

protected function getConnectionHash(array $params): string
{
return sha1(json_encode($params));
}

protected function getConnection(string $key): ?Connection
{
return self::$connections[$key] ?? null;
}

protected function addConnection(string $key, Connection $connection): void
{
self::$connections[$key] = $connection;
}

private function getPlatform(Connection $connection, array $params): AbstractPlatform
{
if (isset($params['platform'])) {
Expand Down

0 comments on commit a0e788e

Please sign in to comment.