forked from php-db/phpdb-sqlite
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPdoDriverInterfaceFactory.php
More file actions
48 lines (41 loc) · 1.5 KB
/
PdoDriverInterfaceFactory.php
File metadata and controls
48 lines (41 loc) · 1.5 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
40
41
42
43
44
45
46
47
48
<?php
declare(strict_types=1);
namespace PhpDb\Sqlite\Container;
use Laminas\ServiceManager\ServiceManager;
use PhpDb\Adapter\Driver\Pdo\Result;
use PhpDb\Adapter\Driver\Pdo\Statement;
use PhpDb\Adapter\Driver\PdoDriverInterface;
use PhpDb\Adapter\Driver\ResultInterface;
use PhpDb\Sqlite\Pdo;
use Psr\Container\ContainerInterface;
final class PdoDriverInterfaceFactory
{
public function __invoke(
ContainerInterface&ServiceManager $container,
string $requestedName,
?array $options = null
): PdoDriverInterface&Pdo\Driver {
// if (! $container->has('config')) {
// throw ContainerException::forService(
// Pdo\Driver::class,
// self::class,
// 'Container is missing config service'
// );
// }
/** @var Pdo\Connection $connectionInstance */
$connectionInstance = $container->build(
Pdo\Connection::class,
['connection' => $options['connection'] ?? []]
);
/** @var ResultInterface&Result $resultInstance */
$resultInstance = $container->has(ResultInterface::class)
? $container->get(ResultInterface::class)
: new Result();
return new Pdo\Driver(
connection:$connectionInstance,
statementPrototype: $container->build(Statement::class, $options['options'] ?? []),
resultPrototype: $resultInstance,
features: [new Pdo\Feature\SqliteRowCounter()],
);
}
}