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

Added the ability to extend StaticDriver for greater flexibility #291

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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