forked from php-db/phpdb-pgsql
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathConnectionInterfaceFactory.php
More file actions
39 lines (34 loc) · 1.09 KB
/
ConnectionInterfaceFactory.php
File metadata and controls
39 lines (34 loc) · 1.09 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
<?php
declare(strict_types=1);
namespace PhpDb\Pgsql\Container;
use PhpDb\Adapter\Driver\ConnectionInterface;
use PhpDb\Adapter\Exception\InvalidConnectionParametersException;
use PhpDb\Adapter\Pgsql\Exception\ContainerException;
use PhpDb\Pgsql\Connection;
use Psr\Container\ContainerInterface;
use function is_array;
/**
* This factory can only be used via the ServiceManager's build() method
*
* @internal
*/
final class ConnectionInterfaceFactory
{
/**
* @throws ContainerException
* @throws InvalidConnectionParametersException
*/
public function __invoke(
ContainerInterface $container,
string $requestedName,
?array $options = null
): ConnectionInterface&Connection {
if (! is_array($options['connection']) || $options['connection'] === []) {
throw new InvalidConnectionParametersException(
'Connection configuration must be an array of parameters passed via $options["connection"]',
$options['connection']
);
}
return new Connection($options['connection']);
}
}