|
4 | 4 |
|
5 | 5 | namespace PhpDb\Sqlite\Container; |
6 | 6 |
|
7 | | -use PhpDb\Adapter\AdapterInterface; |
8 | | -use PhpDb\Adapter\Driver\ConnectionInterface; |
| 7 | +use PhpDb\Adapter\Driver\PdoConnectionInterface; |
| 8 | +use PhpDb\Adapter\Exception\InvalidConnectionParametersException; |
9 | 9 | use PhpDb\Sqlite\Pdo\Connection; |
10 | 10 | use Psr\Container\ContainerInterface; |
11 | 11 |
|
| 12 | +use function is_array; |
| 13 | + |
12 | 14 | final class PdoConnectionFactory |
13 | 15 | { |
14 | | - public function __invoke(ContainerInterface $container): ConnectionInterface&Connection |
15 | | - { |
16 | | - /** @var array $config */ |
17 | | - $config = $container->get('config'); |
18 | | - |
19 | | - /** @var array $dbConfig */ |
20 | | - $dbConfig = $config[AdapterInterface::class] ?? []; |
21 | | - |
22 | | - /** @var array $connectionConfig */ |
23 | | - $connectionConfig = $dbConfig['connection'] ?? []; |
| 16 | + public function __invoke( |
| 17 | + ContainerInterface $container, |
| 18 | + string $requestedName, |
| 19 | + ?array $options = null |
| 20 | + ): PdoConnectionInterface&Connection { |
| 21 | + $conn = $options['connection'] ?? []; |
| 22 | + if (! is_array($conn) || $conn === []) { |
| 23 | + throw new InvalidConnectionParametersException( |
| 24 | + 'Connection configuration must be an array of parameters passed via $options["connection"]', |
| 25 | + $conn |
| 26 | + ); |
| 27 | + } |
24 | 28 |
|
25 | | - return new Connection($connectionConfig); |
| 29 | + return new Connection($conn); |
26 | 30 | } |
27 | 31 | } |
0 commit comments