Subversion-Projekte lars-tiefland.laravel_shop

Revision

Revision 148 | Details | Vergleich mit vorheriger | Letzte Änderung | Log anzeigen | RSS feed

Revision Autor Zeilennr. Zeile
148 lars 1
<?php
2
 
3
namespace Doctrine\DBAL\Driver\SQLite3;
4
 
5
use Doctrine\DBAL\Driver\AbstractSQLiteDriver;
6
use Doctrine\DBAL\Driver\API\SQLite\UserDefinedFunctions;
621 lars 7
use SensitiveParameter;
148 lars 8
use SQLite3;
9
 
10
final class Driver extends AbstractSQLiteDriver
11
{
12
    /**
13
     * {@inheritdoc}
14
     */
621 lars 15
    public function connect(
16
        #[SensitiveParameter]
17
        array $params
18
    ): Connection {
148 lars 19
        $isMemory = (bool) ($params['memory'] ?? false);
20
 
21
        if (isset($params['path'])) {
22
            if ($isMemory) {
23
                throw new Exception(
24
                    'Invalid connection settings: specifying both parameters "path" and "memory" is ambiguous.',
25
                );
26
            }
27
 
28
            $filename = $params['path'];
29
        } elseif ($isMemory) {
30
            $filename = ':memory:';
31
        } else {
32
            throw new Exception(
33
                'Invalid connection settings: specify either the "path" or the "memory" parameter for SQLite3.',
34
            );
35
        }
36
 
37
        try {
38
            $connection = new SQLite3($filename);
39
        } catch (\Exception $e) {
40
            throw Exception::new($e);
41
        }
42
 
43
        $connection->enableExceptions(true);
44
 
45
        UserDefinedFunctions::register([$connection, 'createFunction']);
46
 
47
        return new Connection($connection);
48
    }
49
}