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\PDO\SQLite;
4
 
5
use Doctrine\DBAL\Driver\AbstractSQLiteDriver;
6
use Doctrine\DBAL\Driver\API\SQLite\UserDefinedFunctions;
7
use Doctrine\DBAL\Driver\PDO\Connection;
8
use Doctrine\DBAL\Driver\PDO\Exception;
9
use Doctrine\Deprecations\Deprecation;
10
use PDO;
11
use PDOException;
621 lars 12
use SensitiveParameter;
148 lars 13
 
621 lars 14
use function array_intersect_key;
15
 
148 lars 16
final class Driver extends AbstractSQLiteDriver
17
{
18
    /**
19
     * {@inheritdoc}
20
     *
21
     * @return Connection
22
     */
621 lars 23
    public function connect(
24
        #[SensitiveParameter]
25
        array $params
26
    ) {
148 lars 27
        $driverOptions        = $params['driverOptions'] ?? [];
28
        $userDefinedFunctions = [];
29
 
30
        if (isset($driverOptions['userDefinedFunctions'])) {
31
            Deprecation::trigger(
32
                'doctrine/dbal',
33
                'https://github.com/doctrine/dbal/pull/5742',
34
                'The SQLite-specific driver option "userDefinedFunctions" is deprecated.'
35
                    . ' Register function directly on the native connection instead.',
36
            );
37
 
38
            $userDefinedFunctions = $driverOptions['userDefinedFunctions'];
39
            unset($driverOptions['userDefinedFunctions']);
40
        }
41
 
42
        try {
43
            $pdo = new PDO(
621 lars 44
                $this->constructPdoDsn(array_intersect_key($params, ['path' => true, 'memory' => true])),
148 lars 45
                $params['user'] ?? '',
46
                $params['password'] ?? '',
47
                $driverOptions,
48
            );
49
        } catch (PDOException $exception) {
50
            throw Exception::new($exception);
51
        }
52
 
53
        UserDefinedFunctions::register(
54
            [$pdo, 'sqliteCreateFunction'],
55
            $userDefinedFunctions,
56
        );
57
 
58
        return new Connection($pdo);
59
    }
60
 
61
    /**
62
     * Constructs the Sqlite PDO DSN.
63
     *
621 lars 64
     * @param array<string, mixed> $params
148 lars 65
     */
66
    private function constructPdoDsn(array $params): string
67
    {
68
        $dsn = 'sqlite:';
69
        if (isset($params['path'])) {
70
            $dsn .= $params['path'];
71
        } elseif (isset($params['memory'])) {
72
            $dsn .= ':memory:';
73
        }
74
 
75
        return $dsn;
76
    }
77
}