forked from php-db/phpdb-pgsql
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDriverInterfaceFactory.php
More file actions
35 lines (30 loc) · 1.05 KB
/
DriverInterfaceFactory.php
File metadata and controls
35 lines (30 loc) · 1.05 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
<?php
declare(strict_types=1);
namespace PhpDb\Adapter\Pgsql\Container;
use Laminas\ServiceManager\ServiceManager;
use PhpDb\Adapter\Driver\DriverInterface;
use PhpDb\Adapter\Pgsql;
use PhpDb\Exception\ContainerException;
use Psr\Container\ContainerInterface;
final class DriverInterfaceFactory
{
public function __invoke(
ContainerInterface&ServiceManager $container,
string $requestedName,
?array $options = null
): DriverInterface {
if (! $options['connection']) {
throw ContainerException::forService(
Pgsql\Driver::class,
self::class,
'$options["connection"] must contain an array of connection configuration.'
);
}
$connection = $container->build(Pgsql\Connection::class, $options);
return new Pgsql\Driver(
connection:$connection,
statementPrototype: $container->build(Pgsql\Statement::class, ['options' => $options['options'] ?? []]),
resultPrototype: new Pgsql\Result(),
);
}
}