diff options
author | polo <ordipolo@gmx.fr> | 2024-08-13 23:45:21 +0200 |
---|---|---|
committer | polo <ordipolo@gmx.fr> | 2024-08-13 23:45:21 +0200 |
commit | bf6655a534a6775d30cafa67bd801276bda1d98d (patch) | |
tree | c6381e3f6c81c33eab72508f410b165ba05f7e9c /vendor/doctrine/dbal/src/Driver/PDO | |
parent | 94d67a4b51f8e62e7d518cce26a526ae1ec48278 (diff) | |
download | AppliGestionPHP-bf6655a534a6775d30cafa67bd801276bda1d98d.zip |
VERSION 0.2 doctrine ORM et entités
Diffstat (limited to 'vendor/doctrine/dbal/src/Driver/PDO')
-rw-r--r-- | vendor/doctrine/dbal/src/Driver/PDO/Connection.php | 133 | ||||
-rw-r--r-- | vendor/doctrine/dbal/src/Driver/PDO/Exception.php | 30 | ||||
-rw-r--r-- | vendor/doctrine/dbal/src/Driver/PDO/MySQL/Driver.php | 76 | ||||
-rw-r--r-- | vendor/doctrine/dbal/src/Driver/PDO/OCI/Driver.php | 61 | ||||
-rw-r--r-- | vendor/doctrine/dbal/src/Driver/PDO/PgSQL/Driver.php | 113 | ||||
-rw-r--r-- | vendor/doctrine/dbal/src/Driver/PDO/Result.php | 110 | ||||
-rw-r--r-- | vendor/doctrine/dbal/src/Driver/PDO/SQLSrv/Connection.php | 29 | ||||
-rw-r--r-- | vendor/doctrine/dbal/src/Driver/PDO/SQLSrv/Driver.php | 108 | ||||
-rw-r--r-- | vendor/doctrine/dbal/src/Driver/PDO/SQLSrv/Statement.php | 46 | ||||
-rw-r--r-- | vendor/doctrine/dbal/src/Driver/PDO/SQLite/Driver.php | 55 | ||||
-rw-r--r-- | vendor/doctrine/dbal/src/Driver/PDO/Statement.php | 80 |
11 files changed, 841 insertions, 0 deletions
diff --git a/vendor/doctrine/dbal/src/Driver/PDO/Connection.php b/vendor/doctrine/dbal/src/Driver/PDO/Connection.php new file mode 100644 index 0000000..b1faca1 --- /dev/null +++ b/vendor/doctrine/dbal/src/Driver/PDO/Connection.php | |||
@@ -0,0 +1,133 @@ | |||
1 | <?php | ||
2 | |||
3 | declare(strict_types=1); | ||
4 | |||
5 | namespace Doctrine\DBAL\Driver\PDO; | ||
6 | |||
7 | use Doctrine\DBAL\Driver\Connection as ConnectionInterface; | ||
8 | use Doctrine\DBAL\Driver\Exception\IdentityColumnsNotSupported; | ||
9 | use Doctrine\DBAL\Driver\Exception\NoIdentityValue; | ||
10 | use PDO; | ||
11 | use PDOException; | ||
12 | use PDOStatement; | ||
13 | |||
14 | use function assert; | ||
15 | |||
16 | final class Connection implements ConnectionInterface | ||
17 | { | ||
18 | /** @internal The connection can be only instantiated by its driver. */ | ||
19 | public function __construct(private readonly PDO $connection) | ||
20 | { | ||
21 | $connection->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); | ||
22 | } | ||
23 | |||
24 | public function exec(string $sql): int | ||
25 | { | ||
26 | try { | ||
27 | $result = $this->connection->exec($sql); | ||
28 | |||
29 | assert($result !== false); | ||
30 | |||
31 | return $result; | ||
32 | } catch (PDOException $exception) { | ||
33 | throw Exception::new($exception); | ||
34 | } | ||
35 | } | ||
36 | |||
37 | public function getServerVersion(): string | ||
38 | { | ||
39 | return $this->connection->getAttribute(PDO::ATTR_SERVER_VERSION); | ||
40 | } | ||
41 | |||
42 | public function prepare(string $sql): Statement | ||
43 | { | ||
44 | try { | ||
45 | $stmt = $this->connection->prepare($sql); | ||
46 | assert($stmt instanceof PDOStatement); | ||
47 | |||
48 | return new Statement($stmt); | ||
49 | } catch (PDOException $exception) { | ||
50 | throw Exception::new($exception); | ||
51 | } | ||
52 | } | ||
53 | |||
54 | public function query(string $sql): Result | ||
55 | { | ||
56 | try { | ||
57 | $stmt = $this->connection->query($sql); | ||
58 | assert($stmt instanceof PDOStatement); | ||
59 | |||
60 | return new Result($stmt); | ||
61 | } catch (PDOException $exception) { | ||
62 | throw Exception::new($exception); | ||
63 | } | ||
64 | } | ||
65 | |||
66 | public function quote(string $value): string | ||
67 | { | ||
68 | return $this->connection->quote($value); | ||
69 | } | ||
70 | |||
71 | public function lastInsertId(): int|string | ||
72 | { | ||
73 | try { | ||
74 | $value = $this->connection->lastInsertId(); | ||
75 | } catch (PDOException $exception) { | ||
76 | assert($exception->errorInfo !== null); | ||
77 | [$sqlState] = $exception->errorInfo; | ||
78 | |||
79 | // if the PDO driver does not support this capability, PDO::lastInsertId() triggers an IM001 SQLSTATE | ||
80 | // see https://www.php.net/manual/en/pdo.lastinsertid.php | ||
81 | if ($sqlState === 'IM001') { | ||
82 | throw IdentityColumnsNotSupported::new(); | ||
83 | } | ||
84 | |||
85 | // PDO PGSQL throws a 'lastval is not yet defined in this session' error when no identity value is | ||
86 | // available, with SQLSTATE 55000 'Object Not In Prerequisite State' | ||
87 | if ($sqlState === '55000' && $this->connection->getAttribute(PDO::ATTR_DRIVER_NAME) === 'pgsql') { | ||
88 | throw NoIdentityValue::new($exception); | ||
89 | } | ||
90 | |||
91 | throw Exception::new($exception); | ||
92 | } | ||
93 | |||
94 | // pdo_mysql & pdo_sqlite return '0', pdo_sqlsrv returns '' or false depending on the PHP version | ||
95 | if ($value === '0' || $value === '' || $value === false) { | ||
96 | throw NoIdentityValue::new(); | ||
97 | } | ||
98 | |||
99 | return $value; | ||
100 | } | ||
101 | |||
102 | public function beginTransaction(): void | ||
103 | { | ||
104 | try { | ||
105 | $this->connection->beginTransaction(); | ||
106 | } catch (PDOException $exception) { | ||
107 | throw Exception::new($exception); | ||
108 | } | ||
109 | } | ||
110 | |||
111 | public function commit(): void | ||
112 | { | ||
113 | try { | ||
114 | $this->connection->commit(); | ||
115 | } catch (PDOException $exception) { | ||
116 | throw Exception::new($exception); | ||
117 | } | ||
118 | } | ||
119 | |||
120 | public function rollBack(): void | ||
121 | { | ||
122 | try { | ||
123 | $this->connection->rollBack(); | ||
124 | } catch (PDOException $exception) { | ||
125 | throw Exception::new($exception); | ||
126 | } | ||
127 | } | ||
128 | |||
129 | public function getNativeConnection(): PDO | ||
130 | { | ||
131 | return $this->connection; | ||
132 | } | ||
133 | } | ||
diff --git a/vendor/doctrine/dbal/src/Driver/PDO/Exception.php b/vendor/doctrine/dbal/src/Driver/PDO/Exception.php new file mode 100644 index 0000000..fbb8125 --- /dev/null +++ b/vendor/doctrine/dbal/src/Driver/PDO/Exception.php | |||
@@ -0,0 +1,30 @@ | |||
1 | <?php | ||
2 | |||
3 | declare(strict_types=1); | ||
4 | |||
5 | namespace Doctrine\DBAL\Driver\PDO; | ||
6 | |||
7 | use Doctrine\DBAL\Driver\AbstractException; | ||
8 | use PDOException; | ||
9 | |||
10 | /** | ||
11 | * @internal | ||
12 | * | ||
13 | * @psalm-immutable | ||
14 | */ | ||
15 | final class Exception extends AbstractException | ||
16 | { | ||
17 | public static function new(PDOException $exception): self | ||
18 | { | ||
19 | if ($exception->errorInfo !== null) { | ||
20 | [$sqlState, $code] = $exception->errorInfo; | ||
21 | |||
22 | $code ??= 0; | ||
23 | } else { | ||
24 | $code = $exception->getCode(); | ||
25 | $sqlState = null; | ||
26 | } | ||
27 | |||
28 | return new self($exception->getMessage(), $sqlState, $code, $exception); | ||
29 | } | ||
30 | } | ||
diff --git a/vendor/doctrine/dbal/src/Driver/PDO/MySQL/Driver.php b/vendor/doctrine/dbal/src/Driver/PDO/MySQL/Driver.php new file mode 100644 index 0000000..963fef0 --- /dev/null +++ b/vendor/doctrine/dbal/src/Driver/PDO/MySQL/Driver.php | |||
@@ -0,0 +1,76 @@ | |||
1 | <?php | ||
2 | |||
3 | declare(strict_types=1); | ||
4 | |||
5 | namespace Doctrine\DBAL\Driver\PDO\MySQL; | ||
6 | |||
7 | use Doctrine\DBAL\Driver\AbstractMySQLDriver; | ||
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 | final class Driver extends AbstractMySQLDriver | ||
15 | { | ||
16 | /** | ||
17 | * {@inheritDoc} | ||
18 | */ | ||
19 | public function connect( | ||
20 | #[SensitiveParameter] | ||
21 | array $params, | ||
22 | ): Connection { | ||
23 | $driverOptions = $params['driverOptions'] ?? []; | ||
24 | |||
25 | if (! empty($params['persistent'])) { | ||
26 | $driverOptions[PDO::ATTR_PERSISTENT] = true; | ||
27 | } | ||
28 | |||
29 | $safeParams = $params; | ||
30 | unset($safeParams['password']); | ||
31 | |||
32 | try { | ||
33 | $pdo = new PDO( | ||
34 | $this->constructPdoDsn($safeParams), | ||
35 | $params['user'] ?? '', | ||
36 | $params['password'] ?? '', | ||
37 | $driverOptions, | ||
38 | ); | ||
39 | } catch (PDOException $exception) { | ||
40 | throw Exception::new($exception); | ||
41 | } | ||
42 | |||
43 | return new Connection($pdo); | ||
44 | } | ||
45 | |||
46 | /** | ||
47 | * Constructs the MySQL PDO DSN. | ||
48 | * | ||
49 | * @param mixed[] $params | ||
50 | */ | ||
51 | private function constructPdoDsn(array $params): string | ||
52 | { | ||
53 | $dsn = 'mysql:'; | ||
54 | if (isset($params['host']) && $params['host'] !== '') { | ||
55 | $dsn .= 'host=' . $params['host'] . ';'; | ||
56 | } | ||
57 | |||
58 | if (isset($params['port'])) { | ||
59 | $dsn .= 'port=' . $params['port'] . ';'; | ||
60 | } | ||
61 | |||
62 | if (isset($params['dbname'])) { | ||
63 | $dsn .= 'dbname=' . $params['dbname'] . ';'; | ||
64 | } | ||
65 | |||
66 | if (isset($params['unix_socket'])) { | ||
67 | $dsn .= 'unix_socket=' . $params['unix_socket'] . ';'; | ||
68 | } | ||
69 | |||
70 | if (isset($params['charset'])) { | ||
71 | $dsn .= 'charset=' . $params['charset'] . ';'; | ||
72 | } | ||
73 | |||
74 | return $dsn; | ||
75 | } | ||
76 | } | ||
diff --git a/vendor/doctrine/dbal/src/Driver/PDO/OCI/Driver.php b/vendor/doctrine/dbal/src/Driver/PDO/OCI/Driver.php new file mode 100644 index 0000000..4c02de1 --- /dev/null +++ b/vendor/doctrine/dbal/src/Driver/PDO/OCI/Driver.php | |||
@@ -0,0 +1,61 @@ | |||
1 | <?php | ||
2 | |||
3 | declare(strict_types=1); | ||
4 | |||
5 | namespace Doctrine\DBAL\Driver\PDO\OCI; | ||
6 | |||
7 | use Doctrine\DBAL\Driver\AbstractOracleDriver; | ||
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 | final class Driver extends AbstractOracleDriver | ||
15 | { | ||
16 | /** | ||
17 | * {@inheritDoc} | ||
18 | */ | ||
19 | public function connect( | ||
20 | #[SensitiveParameter] | ||
21 | array $params, | ||
22 | ): Connection { | ||
23 | $driverOptions = $params['driverOptions'] ?? []; | ||
24 | |||
25 | if (! empty($params['persistent'])) { | ||
26 | $driverOptions[PDO::ATTR_PERSISTENT] = true; | ||
27 | } | ||
28 | |||
29 | $safeParams = $params; | ||
30 | unset($safeParams['password']); | ||
31 | |||
32 | try { | ||
33 | $pdo = new PDO( | ||
34 | $this->constructPdoDsn($params), | ||
35 | $params['user'] ?? '', | ||
36 | $params['password'] ?? '', | ||
37 | $driverOptions, | ||
38 | ); | ||
39 | } catch (PDOException $exception) { | ||
40 | throw Exception::new($exception); | ||
41 | } | ||
42 | |||
43 | return new Connection($pdo); | ||
44 | } | ||
45 | |||
46 | /** | ||
47 | * Constructs the Oracle PDO DSN. | ||
48 | * | ||
49 | * @param mixed[] $params | ||
50 | */ | ||
51 | private function constructPdoDsn(array $params): string | ||
52 | { | ||
53 | $dsn = 'oci:dbname=' . $this->getEasyConnectString($params); | ||
54 | |||
55 | if (isset($params['charset'])) { | ||
56 | $dsn .= ';charset=' . $params['charset']; | ||
57 | } | ||
58 | |||
59 | return $dsn; | ||
60 | } | ||
61 | } | ||
diff --git a/vendor/doctrine/dbal/src/Driver/PDO/PgSQL/Driver.php b/vendor/doctrine/dbal/src/Driver/PDO/PgSQL/Driver.php new file mode 100644 index 0000000..a267e84 --- /dev/null +++ b/vendor/doctrine/dbal/src/Driver/PDO/PgSQL/Driver.php | |||
@@ -0,0 +1,113 @@ | |||
1 | <?php | ||
2 | |||
3 | declare(strict_types=1); | ||
4 | |||
5 | namespace Doctrine\DBAL\Driver\PDO\PgSQL; | ||
6 | |||
7 | use Doctrine\DBAL\Driver\AbstractPostgreSQLDriver; | ||
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 | final class Driver extends AbstractPostgreSQLDriver | ||
15 | { | ||
16 | /** | ||
17 | * {@inheritDoc} | ||
18 | */ | ||
19 | public function connect( | ||
20 | #[SensitiveParameter] | ||
21 | array $params, | ||
22 | ): Connection { | ||
23 | $driverOptions = $params['driverOptions'] ?? []; | ||
24 | |||
25 | if (! empty($params['persistent'])) { | ||
26 | $driverOptions[PDO::ATTR_PERSISTENT] = true; | ||
27 | } | ||
28 | |||
29 | $safeParams = $params; | ||
30 | unset($safeParams['password']); | ||
31 | |||
32 | try { | ||
33 | $pdo = new PDO( | ||
34 | $this->constructPdoDsn($safeParams), | ||
35 | $params['user'] ?? '', | ||
36 | $params['password'] ?? '', | ||
37 | $driverOptions, | ||
38 | ); | ||
39 | } catch (PDOException $exception) { | ||
40 | throw Exception::new($exception); | ||
41 | } | ||
42 | |||
43 | if ( | ||
44 | ! isset($driverOptions[PDO::PGSQL_ATTR_DISABLE_PREPARES]) | ||
45 | || $driverOptions[PDO::PGSQL_ATTR_DISABLE_PREPARES] === true | ||
46 | ) { | ||
47 | $pdo->setAttribute(PDO::PGSQL_ATTR_DISABLE_PREPARES, true); | ||
48 | } | ||
49 | |||
50 | $connection = new Connection($pdo); | ||
51 | |||
52 | /* defining client_encoding via SET NAMES to avoid inconsistent DSN support | ||
53 | * - passing client_encoding via the 'options' param breaks pgbouncer support | ||
54 | */ | ||
55 | if (isset($params['charset'])) { | ||
56 | $connection->exec('SET NAMES \'' . $params['charset'] . '\''); | ||
57 | } | ||
58 | |||
59 | return $connection; | ||
60 | } | ||
61 | |||
62 | /** | ||
63 | * Constructs the Postgres PDO DSN. | ||
64 | * | ||
65 | * @param array<string, mixed> $params | ||
66 | */ | ||
67 | private function constructPdoDsn(array $params): string | ||
68 | { | ||
69 | $dsn = 'pgsql:'; | ||
70 | |||
71 | if (isset($params['host']) && $params['host'] !== '') { | ||
72 | $dsn .= 'host=' . $params['host'] . ';'; | ||
73 | } | ||
74 | |||
75 | if (isset($params['port']) && $params['port'] !== '') { | ||
76 | $dsn .= 'port=' . $params['port'] . ';'; | ||
77 | } | ||
78 | |||
79 | if (isset($params['dbname'])) { | ||
80 | $dsn .= 'dbname=' . $params['dbname'] . ';'; | ||
81 | } | ||
82 | |||
83 | if (isset($params['sslmode'])) { | ||
84 | $dsn .= 'sslmode=' . $params['sslmode'] . ';'; | ||
85 | } | ||
86 | |||
87 | if (isset($params['sslrootcert'])) { | ||
88 | $dsn .= 'sslrootcert=' . $params['sslrootcert'] . ';'; | ||
89 | } | ||
90 | |||
91 | if (isset($params['sslcert'])) { | ||
92 | $dsn .= 'sslcert=' . $params['sslcert'] . ';'; | ||
93 | } | ||
94 | |||
95 | if (isset($params['sslkey'])) { | ||
96 | $dsn .= 'sslkey=' . $params['sslkey'] . ';'; | ||
97 | } | ||
98 | |||
99 | if (isset($params['sslcrl'])) { | ||
100 | $dsn .= 'sslcrl=' . $params['sslcrl'] . ';'; | ||
101 | } | ||
102 | |||
103 | if (isset($params['application_name'])) { | ||
104 | $dsn .= 'application_name=' . $params['application_name'] . ';'; | ||
105 | } | ||
106 | |||
107 | if (isset($params['gssencmode'])) { | ||
108 | $dsn .= 'gssencmode=' . $params['gssencmode'] . ';'; | ||
109 | } | ||
110 | |||
111 | return $dsn; | ||
112 | } | ||
113 | } | ||
diff --git a/vendor/doctrine/dbal/src/Driver/PDO/Result.php b/vendor/doctrine/dbal/src/Driver/PDO/Result.php new file mode 100644 index 0000000..1a844d1 --- /dev/null +++ b/vendor/doctrine/dbal/src/Driver/PDO/Result.php | |||
@@ -0,0 +1,110 @@ | |||
1 | <?php | ||
2 | |||
3 | declare(strict_types=1); | ||
4 | |||
5 | namespace Doctrine\DBAL\Driver\PDO; | ||
6 | |||
7 | use Doctrine\DBAL\Driver\Result as ResultInterface; | ||
8 | use PDO; | ||
9 | use PDOException; | ||
10 | use PDOStatement; | ||
11 | |||
12 | final class Result implements ResultInterface | ||
13 | { | ||
14 | /** @internal The result can be only instantiated by its driver connection or statement. */ | ||
15 | public function __construct(private readonly PDOStatement $statement) | ||
16 | { | ||
17 | } | ||
18 | |||
19 | public function fetchNumeric(): array|false | ||
20 | { | ||
21 | return $this->fetch(PDO::FETCH_NUM); | ||
22 | } | ||
23 | |||
24 | public function fetchAssociative(): array|false | ||
25 | { | ||
26 | return $this->fetch(PDO::FETCH_ASSOC); | ||
27 | } | ||
28 | |||
29 | public function fetchOne(): mixed | ||
30 | { | ||
31 | return $this->fetch(PDO::FETCH_COLUMN); | ||
32 | } | ||
33 | |||
34 | /** | ||
35 | * {@inheritDoc} | ||
36 | */ | ||
37 | public function fetchAllNumeric(): array | ||
38 | { | ||
39 | return $this->fetchAll(PDO::FETCH_NUM); | ||
40 | } | ||
41 | |||
42 | /** | ||
43 | * {@inheritDoc} | ||
44 | */ | ||
45 | public function fetchAllAssociative(): array | ||
46 | { | ||
47 | return $this->fetchAll(PDO::FETCH_ASSOC); | ||
48 | } | ||
49 | |||
50 | /** | ||
51 | * {@inheritDoc} | ||
52 | */ | ||
53 | public function fetchFirstColumn(): array | ||
54 | { | ||
55 | return $this->fetchAll(PDO::FETCH_COLUMN); | ||
56 | } | ||
57 | |||
58 | public function rowCount(): int | ||
59 | { | ||
60 | try { | ||
61 | return $this->statement->rowCount(); | ||
62 | } catch (PDOException $exception) { | ||
63 | throw Exception::new($exception); | ||
64 | } | ||
65 | } | ||
66 | |||
67 | public function columnCount(): int | ||
68 | { | ||
69 | try { | ||
70 | return $this->statement->columnCount(); | ||
71 | } catch (PDOException $exception) { | ||
72 | throw Exception::new($exception); | ||
73 | } | ||
74 | } | ||
75 | |||
76 | public function free(): void | ||
77 | { | ||
78 | $this->statement->closeCursor(); | ||
79 | } | ||
80 | |||
81 | /** | ||
82 | * @psalm-param PDO::FETCH_* $mode | ||
83 | * | ||
84 | * @throws Exception | ||
85 | */ | ||
86 | private function fetch(int $mode): mixed | ||
87 | { | ||
88 | try { | ||
89 | return $this->statement->fetch($mode); | ||
90 | } catch (PDOException $exception) { | ||
91 | throw Exception::new($exception); | ||
92 | } | ||
93 | } | ||
94 | |||
95 | /** | ||
96 | * @psalm-param PDO::FETCH_* $mode | ||
97 | * | ||
98 | * @return list<mixed> | ||
99 | * | ||
100 | * @throws Exception | ||
101 | */ | ||
102 | private function fetchAll(int $mode): array | ||
103 | { | ||
104 | try { | ||
105 | return $this->statement->fetchAll($mode); | ||
106 | } catch (PDOException $exception) { | ||
107 | throw Exception::new($exception); | ||
108 | } | ||
109 | } | ||
110 | } | ||
diff --git a/vendor/doctrine/dbal/src/Driver/PDO/SQLSrv/Connection.php b/vendor/doctrine/dbal/src/Driver/PDO/SQLSrv/Connection.php new file mode 100644 index 0000000..78ba7f8 --- /dev/null +++ b/vendor/doctrine/dbal/src/Driver/PDO/SQLSrv/Connection.php | |||
@@ -0,0 +1,29 @@ | |||
1 | <?php | ||
2 | |||
3 | declare(strict_types=1); | ||
4 | |||
5 | namespace Doctrine\DBAL\Driver\PDO\SQLSrv; | ||
6 | |||
7 | use Doctrine\DBAL\Driver\Middleware\AbstractConnectionMiddleware; | ||
8 | use Doctrine\DBAL\Driver\PDO\Connection as PDOConnection; | ||
9 | use PDO; | ||
10 | |||
11 | final class Connection extends AbstractConnectionMiddleware | ||
12 | { | ||
13 | public function __construct(private readonly PDOConnection $connection) | ||
14 | { | ||
15 | parent::__construct($connection); | ||
16 | } | ||
17 | |||
18 | public function prepare(string $sql): Statement | ||
19 | { | ||
20 | return new Statement( | ||
21 | $this->connection->prepare($sql), | ||
22 | ); | ||
23 | } | ||
24 | |||
25 | public function getNativeConnection(): PDO | ||
26 | { | ||
27 | return $this->connection->getNativeConnection(); | ||
28 | } | ||
29 | } | ||
diff --git a/vendor/doctrine/dbal/src/Driver/PDO/SQLSrv/Driver.php b/vendor/doctrine/dbal/src/Driver/PDO/SQLSrv/Driver.php new file mode 100644 index 0000000..a3cae97 --- /dev/null +++ b/vendor/doctrine/dbal/src/Driver/PDO/SQLSrv/Driver.php | |||
@@ -0,0 +1,108 @@ | |||
1 | <?php | ||
2 | |||
3 | declare(strict_types=1); | ||
4 | |||
5 | namespace Doctrine\DBAL\Driver\PDO\SQLSrv; | ||
6 | |||
7 | use Doctrine\DBAL\Driver\AbstractSQLServerDriver; | ||
8 | use Doctrine\DBAL\Driver\AbstractSQLServerDriver\Exception\PortWithoutHost; | ||
9 | use Doctrine\DBAL\Driver\Exception; | ||
10 | use Doctrine\DBAL\Driver\PDO\Connection as PDOConnection; | ||
11 | use Doctrine\DBAL\Driver\PDO\Exception as PDOException; | ||
12 | use PDO; | ||
13 | use SensitiveParameter; | ||
14 | |||
15 | use function is_int; | ||
16 | use function sprintf; | ||
17 | |||
18 | final class Driver extends AbstractSQLServerDriver | ||
19 | { | ||
20 | /** | ||
21 | * {@inheritDoc} | ||
22 | */ | ||
23 | public function connect( | ||
24 | #[SensitiveParameter] | ||
25 | array $params, | ||
26 | ): Connection { | ||
27 | $driverOptions = $dsnOptions = []; | ||
28 | |||
29 | if (isset($params['driverOptions'])) { | ||
30 | foreach ($params['driverOptions'] as $option => $value) { | ||
31 | if (is_int($option)) { | ||
32 | $driverOptions[$option] = $value; | ||
33 | } else { | ||
34 | $dsnOptions[$option] = $value; | ||
35 | } | ||
36 | } | ||
37 | } | ||
38 | |||
39 | if (! empty($params['persistent'])) { | ||
40 | $driverOptions[PDO::ATTR_PERSISTENT] = true; | ||
41 | } | ||
42 | |||
43 | $safeParams = $params; | ||
44 | unset($safeParams['password']); | ||
45 | |||
46 | try { | ||
47 | $pdo = new PDO( | ||
48 | $this->constructDsn($safeParams, $dsnOptions), | ||
49 | $params['user'] ?? '', | ||
50 | $params['password'] ?? '', | ||
51 | $driverOptions, | ||
52 | ); | ||
53 | } catch (\PDOException $exception) { | ||
54 | throw PDOException::new($exception); | ||
55 | } | ||
56 | |||
57 | return new Connection(new PDOConnection($pdo)); | ||
58 | } | ||
59 | |||
60 | /** | ||
61 | * Constructs the Sqlsrv PDO DSN. | ||
62 | * | ||
63 | * @param mixed[] $params | ||
64 | * @param string[] $connectionOptions | ||
65 | * | ||
66 | * @throws Exception | ||
67 | */ | ||
68 | private function constructDsn(array $params, array $connectionOptions): string | ||
69 | { | ||
70 | $dsn = 'sqlsrv:server='; | ||
71 | |||
72 | if (isset($params['host'])) { | ||
73 | $dsn .= $params['host']; | ||
74 | |||
75 | if (isset($params['port'])) { | ||
76 | $dsn .= ',' . $params['port']; | ||
77 | } | ||
78 | } elseif (isset($params['port'])) { | ||
79 | throw PortWithoutHost::new(); | ||
80 | } | ||
81 | |||
82 | if (isset($params['dbname'])) { | ||
83 | $connectionOptions['Database'] = $params['dbname']; | ||
84 | } | ||
85 | |||
86 | if (isset($params['MultipleActiveResultSets'])) { | ||
87 | $connectionOptions['MultipleActiveResultSets'] = $params['MultipleActiveResultSets'] ? 'true' : 'false'; | ||
88 | } | ||
89 | |||
90 | return $dsn . $this->getConnectionOptionsDsn($connectionOptions); | ||
91 | } | ||
92 | |||
93 | /** | ||
94 | * Converts a connection options array to the DSN | ||
95 | * | ||
96 | * @param string[] $connectionOptions | ||
97 | */ | ||
98 | private function getConnectionOptionsDsn(array $connectionOptions): string | ||
99 | { | ||
100 | $connectionOptionsDsn = ''; | ||
101 | |||
102 | foreach ($connectionOptions as $paramName => $paramValue) { | ||
103 | $connectionOptionsDsn .= sprintf(';%s=%s', $paramName, $paramValue); | ||
104 | } | ||
105 | |||
106 | return $connectionOptionsDsn; | ||
107 | } | ||
108 | } | ||
diff --git a/vendor/doctrine/dbal/src/Driver/PDO/SQLSrv/Statement.php b/vendor/doctrine/dbal/src/Driver/PDO/SQLSrv/Statement.php new file mode 100644 index 0000000..44cecc9 --- /dev/null +++ b/vendor/doctrine/dbal/src/Driver/PDO/SQLSrv/Statement.php | |||
@@ -0,0 +1,46 @@ | |||
1 | <?php | ||
2 | |||
3 | declare(strict_types=1); | ||
4 | |||
5 | namespace Doctrine\DBAL\Driver\PDO\SQLSrv; | ||
6 | |||
7 | use Doctrine\DBAL\Driver\Middleware\AbstractStatementMiddleware; | ||
8 | use Doctrine\DBAL\Driver\PDO\Statement as PDOStatement; | ||
9 | use Doctrine\DBAL\ParameterType; | ||
10 | use PDO; | ||
11 | |||
12 | final class Statement extends AbstractStatementMiddleware | ||
13 | { | ||
14 | /** @internal The statement can be only instantiated by its driver connection. */ | ||
15 | public function __construct(private readonly PDOStatement $statement) | ||
16 | { | ||
17 | parent::__construct($statement); | ||
18 | } | ||
19 | |||
20 | public function bindValue(int|string $param, mixed $value, ParameterType $type): void | ||
21 | { | ||
22 | switch ($type) { | ||
23 | case ParameterType::LARGE_OBJECT: | ||
24 | case ParameterType::BINARY: | ||
25 | $this->statement->bindParamWithDriverOptions( | ||
26 | $param, | ||
27 | $value, | ||
28 | $type, | ||
29 | PDO::SQLSRV_ENCODING_BINARY, | ||
30 | ); | ||
31 | break; | ||
32 | |||
33 | case ParameterType::ASCII: | ||
34 | $this->statement->bindParamWithDriverOptions( | ||
35 | $param, | ||
36 | $value, | ||
37 | ParameterType::STRING, | ||
38 | PDO::SQLSRV_ENCODING_SYSTEM, | ||
39 | ); | ||
40 | break; | ||
41 | |||
42 | default: | ||
43 | $this->statement->bindValue($param, $value, $type); | ||
44 | } | ||
45 | } | ||
46 | } | ||
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 | } | ||
diff --git a/vendor/doctrine/dbal/src/Driver/PDO/Statement.php b/vendor/doctrine/dbal/src/Driver/PDO/Statement.php new file mode 100644 index 0000000..4f0e070 --- /dev/null +++ b/vendor/doctrine/dbal/src/Driver/PDO/Statement.php | |||
@@ -0,0 +1,80 @@ | |||
1 | <?php | ||
2 | |||
3 | declare(strict_types=1); | ||
4 | |||
5 | namespace Doctrine\DBAL\Driver\PDO; | ||
6 | |||
7 | use Doctrine\DBAL\Driver\Exception as ExceptionInterface; | ||
8 | use Doctrine\DBAL\Driver\Statement as StatementInterface; | ||
9 | use Doctrine\DBAL\ParameterType; | ||
10 | use PDO; | ||
11 | use PDOException; | ||
12 | use PDOStatement; | ||
13 | |||
14 | final class Statement implements StatementInterface | ||
15 | { | ||
16 | /** @internal The statement can be only instantiated by its driver connection. */ | ||
17 | public function __construct(private readonly PDOStatement $stmt) | ||
18 | { | ||
19 | } | ||
20 | |||
21 | public function bindValue(int|string $param, mixed $value, ParameterType $type): void | ||
22 | { | ||
23 | $pdoType = $this->convertParamType($type); | ||
24 | |||
25 | try { | ||
26 | $this->stmt->bindValue($param, $value, $pdoType); | ||
27 | } catch (PDOException $exception) { | ||
28 | throw Exception::new($exception); | ||
29 | } | ||
30 | } | ||
31 | |||
32 | /** | ||
33 | * @internal Driver options can be only specified by a PDO-based driver. | ||
34 | * | ||
35 | * @throws ExceptionInterface | ||
36 | */ | ||
37 | public function bindParamWithDriverOptions( | ||
38 | string|int $param, | ||
39 | mixed &$variable, | ||
40 | ParameterType $type, | ||
41 | mixed $driverOptions, | ||
42 | ): void { | ||
43 | $pdoType = $this->convertParamType($type); | ||
44 | |||
45 | try { | ||
46 | $this->stmt->bindParam($param, $variable, $pdoType, 0, $driverOptions); | ||
47 | } catch (PDOException $exception) { | ||
48 | throw Exception::new($exception); | ||
49 | } | ||
50 | } | ||
51 | |||
52 | public function execute(): Result | ||
53 | { | ||
54 | try { | ||
55 | $this->stmt->execute(); | ||
56 | } catch (PDOException $exception) { | ||
57 | throw Exception::new($exception); | ||
58 | } | ||
59 | |||
60 | return new Result($this->stmt); | ||
61 | } | ||
62 | |||
63 | /** | ||
64 | * Converts DBAL parameter type to PDO parameter type | ||
65 | * | ||
66 | * @psalm-return PDO::PARAM_* | ||
67 | */ | ||
68 | private function convertParamType(ParameterType $type): int | ||
69 | { | ||
70 | return match ($type) { | ||
71 | ParameterType::NULL => PDO::PARAM_NULL, | ||
72 | ParameterType::INTEGER => PDO::PARAM_INT, | ||
73 | ParameterType::STRING, | ||
74 | ParameterType::ASCII => PDO::PARAM_STR, | ||
75 | ParameterType::BINARY, | ||
76 | ParameterType::LARGE_OBJECT => PDO::PARAM_LOB, | ||
77 | ParameterType::BOOLEAN => PDO::PARAM_BOOL, | ||
78 | }; | ||
79 | } | ||
80 | } | ||