diff options
Diffstat (limited to 'vendor/doctrine/dbal/src/Driver/PDO/SQLite')
| -rw-r--r-- | vendor/doctrine/dbal/src/Driver/PDO/SQLite/Driver.php | 55 |
1 files changed, 55 insertions, 0 deletions
diff --git a/vendor/doctrine/dbal/src/Driver/PDO/SQLite/Driver.php b/vendor/doctrine/dbal/src/Driver/PDO/SQLite/Driver.php new file mode 100644 index 0000000..74194a5 --- /dev/null +++ b/vendor/doctrine/dbal/src/Driver/PDO/SQLite/Driver.php | |||
| @@ -0,0 +1,55 @@ | |||
| 1 | <?php | ||
| 2 | |||
| 3 | declare(strict_types=1); | ||
| 4 | |||
| 5 | namespace Doctrine\DBAL\Driver\PDO\SQLite; | ||
| 6 | |||
| 7 | use Doctrine\DBAL\Driver\AbstractSQLiteDriver; | ||
| 8 | use Doctrine\DBAL\Driver\PDO\Connection; | ||
| 9 | use Doctrine\DBAL\Driver\PDO\Exception; | ||
| 10 | use PDO; | ||
| 11 | use PDOException; | ||
| 12 | use SensitiveParameter; | ||
| 13 | |||
| 14 | use function array_intersect_key; | ||
| 15 | |||
| 16 | final class Driver extends AbstractSQLiteDriver | ||
| 17 | { | ||
| 18 | /** | ||
| 19 | * {@inheritDoc} | ||
| 20 | */ | ||
| 21 | public function connect( | ||
| 22 | #[SensitiveParameter] | ||
| 23 | array $params, | ||
| 24 | ): Connection { | ||
| 25 | try { | ||
| 26 | $pdo = new PDO( | ||
| 27 | $this->constructPdoDsn(array_intersect_key($params, ['path' => true, 'memory' => true])), | ||
| 28 | $params['user'] ?? '', | ||
| 29 | $params['password'] ?? '', | ||
| 30 | $params['driverOptions'] ?? [], | ||
| 31 | ); | ||
| 32 | } catch (PDOException $exception) { | ||
| 33 | throw Exception::new($exception); | ||
| 34 | } | ||
| 35 | |||
| 36 | return new Connection($pdo); | ||
| 37 | } | ||
| 38 | |||
| 39 | /** | ||
| 40 | * Constructs the Sqlite PDO DSN. | ||
| 41 | * | ||
| 42 | * @param array<string, mixed> $params | ||
| 43 | */ | ||
| 44 | private function constructPdoDsn(array $params): string | ||
| 45 | { | ||
| 46 | $dsn = 'sqlite:'; | ||
| 47 | if (isset($params['path'])) { | ||
| 48 | $dsn .= $params['path']; | ||
| 49 | } elseif (isset($params['memory'])) { | ||
| 50 | $dsn .= ':memory:'; | ||
| 51 | } | ||
| 52 | |||
| 53 | return $dsn; | ||
| 54 | } | ||
| 55 | } | ||
