Skip to content

Commit

Permalink
make use of connection from the configuration (#267)
Browse files Browse the repository at this point in the history
  • Loading branch information
dgafka authored Nov 11, 2023
1 parent b72f2f4 commit 9a18615
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
2 changes: 1 addition & 1 deletion packages/Dbal/src/DbalReconnectableConnectionFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ public function getConnection(): Connection
public static function getWrappedConnection(object $connection): Connection
{
if ($connection instanceof EcotoneManagerRegistryConnectionFactory) {
return $connection->getRegistry()->getConnection();
return $connection->getConnection();
} else {
$reflectionClass = new ReflectionClass($connection);
$method = $reflectionClass->getMethod('establishConnection');
Expand Down
9 changes: 9 additions & 0 deletions packages/Dbal/src/EcotoneManagerRegistryConnectionFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,22 +4,31 @@

namespace Ecotone\Dbal;

use Doctrine\DBAL\Connection;
use Doctrine\Persistence\ManagerRegistry;
use Enqueue\Dbal\ManagerRegistryConnectionFactory;

final class EcotoneManagerRegistryConnectionFactory extends ManagerRegistryConnectionFactory
{
private ManagerRegistry $registry;
/** @var array<string, string> */
private array $config;

public function __construct(ManagerRegistry $registry, array $config = [])
{
parent::__construct($registry, $config);

$this->registry = $registry;
$this->config = $config;
}

public function getRegistry(): ManagerRegistry
{
return $this->registry;
}

public function getConnection(): Connection
{
return $this->registry->getConnection($this->config['connection_name'] ?? null);
}
}

0 comments on commit 9a18615

Please sign in to comment.