| 148 |
lars |
1 |
<?php
|
|
|
2 |
|
|
|
3 |
namespace Doctrine\DBAL\Tools\Console\ConnectionProvider;
|
|
|
4 |
|
|
|
5 |
use Doctrine\DBAL\Connection;
|
|
|
6 |
use Doctrine\DBAL\Tools\Console\ConnectionNotFound;
|
|
|
7 |
use Doctrine\DBAL\Tools\Console\ConnectionProvider;
|
|
|
8 |
|
|
|
9 |
use function sprintf;
|
|
|
10 |
|
|
|
11 |
class SingleConnectionProvider implements ConnectionProvider
|
|
|
12 |
{
|
|
|
13 |
private Connection $connection;
|
|
|
14 |
|
|
|
15 |
private string $defaultConnectionName;
|
|
|
16 |
|
|
|
17 |
public function __construct(Connection $connection, string $defaultConnectionName = 'default')
|
|
|
18 |
{
|
|
|
19 |
$this->connection = $connection;
|
|
|
20 |
$this->defaultConnectionName = $defaultConnectionName;
|
|
|
21 |
}
|
|
|
22 |
|
|
|
23 |
public function getDefaultConnection(): Connection
|
|
|
24 |
{
|
|
|
25 |
return $this->connection;
|
|
|
26 |
}
|
|
|
27 |
|
|
|
28 |
public function getConnection(string $name): Connection
|
|
|
29 |
{
|
|
|
30 |
if ($name !== $this->defaultConnectionName) {
|
|
|
31 |
throw new ConnectionNotFound(sprintf('Connection with name "%s" does not exist.', $name));
|
|
|
32 |
}
|
|
|
33 |
|
|
|
34 |
return $this->connection;
|
|
|
35 |
}
|
|
|
36 |
}
|