Subversion-Projekte lars-tiefland.laravel_shop

Revision

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