-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
/
Driver.php
46 lines (37 loc) · 1.21 KB
/
Driver.php
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
<?php
namespace Doctrine\DBAL\Driver\SQLite3;
use Doctrine\DBAL\Driver\AbstractSQLiteDriver;
use Doctrine\DBAL\Driver\API\SQLite\UserDefinedFunctions;
use SQLite3;
final class Driver extends AbstractSQLiteDriver
{
/**
* {@inheritdoc}
*/
public function connect(array $params): Connection
{
$isMemory = (bool) ($params['memory'] ?? false);
if (isset($params['path'])) {
if ($isMemory) {
throw new Exception(
'Invalid connection settings: specifying both parameters "path" and "memory" is ambiguous.',
);
}
$filename = $params['path'];
} elseif ($isMemory) {
$filename = ':memory:';
} else {
throw new Exception(
'Invalid connection settings: specify either the "path" or the "memory" parameter for SQLite3.',
);
}
try {
$connection = new SQLite3($filename);
} catch (\Exception $e) {
throw Exception::new($e);
}
$connection->enableExceptions(true);
UserDefinedFunctions::register([$connection, 'createFunction']);
return new Connection($connection);
}
}