blob: 74194a59c387798b6ebd088a9068037c36aa387e (
plain)
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
49
50
51
52
53
54
55
|
<?php
declare(strict_types=1);
namespace Doctrine\DBAL\Driver\PDO\SQLite;
use Doctrine\DBAL\Driver\AbstractSQLiteDriver;
use Doctrine\DBAL\Driver\PDO\Connection;
use Doctrine\DBAL\Driver\PDO\Exception;
use PDO;
use PDOException;
use SensitiveParameter;
use function array_intersect_key;
final class Driver extends AbstractSQLiteDriver
{
/**
* {@inheritDoc}
*/
public function connect(
#[SensitiveParameter]
array $params,
): Connection {
try {
$pdo = new PDO(
$this->constructPdoDsn(array_intersect_key($params, ['path' => true, 'memory' => true])),
$params['user'] ?? '',
$params['password'] ?? '',
$params['driverOptions'] ?? [],
);
} catch (PDOException $exception) {
throw Exception::new($exception);
}
return new Connection($pdo);
}
/**
* Constructs the Sqlite PDO DSN.
*
* @param array<string, mixed> $params
*/
private function constructPdoDsn(array $params): string
{
$dsn = 'sqlite:';
if (isset($params['path'])) {
$dsn .= $params['path'];
} elseif (isset($params['memory'])) {
$dsn .= ':memory:';
}
return $dsn;
}
}
|