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/Mysqli/Driver.php | |
| parent | 94d67a4b51f8e62e7d518cce26a526ae1ec48278 (diff) | |
| download | AppliGestionPHP-bf6655a534a6775d30cafa67bd801276bda1d98d.tar.gz AppliGestionPHP-bf6655a534a6775d30cafa67bd801276bda1d98d.tar.bz2 AppliGestionPHP-bf6655a534a6775d30cafa67bd801276bda1d98d.zip | |
VERSION 0.2 doctrine ORM et entités
Diffstat (limited to 'vendor/doctrine/dbal/src/Driver/Mysqli/Driver.php')
| -rw-r--r-- | vendor/doctrine/dbal/src/Driver/Mysqli/Driver.php | 117 |
1 files changed, 117 insertions, 0 deletions
diff --git a/vendor/doctrine/dbal/src/Driver/Mysqli/Driver.php b/vendor/doctrine/dbal/src/Driver/Mysqli/Driver.php new file mode 100644 index 0000000..9855e56 --- /dev/null +++ b/vendor/doctrine/dbal/src/Driver/Mysqli/Driver.php | |||
| @@ -0,0 +1,117 @@ | |||
| 1 | <?php | ||
| 2 | |||
| 3 | declare(strict_types=1); | ||
| 4 | |||
| 5 | namespace Doctrine\DBAL\Driver\Mysqli; | ||
| 6 | |||
| 7 | use Doctrine\DBAL\Driver\AbstractMySQLDriver; | ||
| 8 | use Doctrine\DBAL\Driver\Mysqli\Exception\ConnectionFailed; | ||
| 9 | use Doctrine\DBAL\Driver\Mysqli\Exception\HostRequired; | ||
| 10 | use Doctrine\DBAL\Driver\Mysqli\Initializer\Charset; | ||
| 11 | use Doctrine\DBAL\Driver\Mysqli\Initializer\Options; | ||
| 12 | use Doctrine\DBAL\Driver\Mysqli\Initializer\Secure; | ||
| 13 | use Generator; | ||
| 14 | use mysqli; | ||
| 15 | use mysqli_sql_exception; | ||
| 16 | use SensitiveParameter; | ||
| 17 | |||
| 18 | final class Driver extends AbstractMySQLDriver | ||
| 19 | { | ||
| 20 | /** | ||
| 21 | * {@inheritDoc} | ||
| 22 | */ | ||
| 23 | public function connect( | ||
| 24 | #[SensitiveParameter] | ||
| 25 | array $params, | ||
| 26 | ): Connection { | ||
| 27 | if (! empty($params['persistent'])) { | ||
| 28 | if (! isset($params['host'])) { | ||
| 29 | throw HostRequired::forPersistentConnection(); | ||
| 30 | } | ||
| 31 | |||
| 32 | $host = 'p:' . $params['host']; | ||
| 33 | } else { | ||
| 34 | $host = $params['host'] ?? ''; | ||
| 35 | } | ||
| 36 | |||
| 37 | $connection = new mysqli(); | ||
| 38 | |||
| 39 | foreach ($this->compilePreInitializers($params) as $initializer) { | ||
| 40 | $initializer->initialize($connection); | ||
| 41 | } | ||
| 42 | |||
| 43 | try { | ||
| 44 | $success = @$connection->real_connect( | ||
| 45 | $host, | ||
| 46 | $params['user'] ?? '', | ||
| 47 | $params['password'] ?? '', | ||
| 48 | $params['dbname'] ?? '', | ||
| 49 | $params['port'] ?? 0, | ||
| 50 | $params['unix_socket'] ?? '', | ||
| 51 | $params['driverOptions'][Connection::OPTION_FLAGS] ?? 0, | ||
| 52 | ); | ||
| 53 | } catch (mysqli_sql_exception $e) { | ||
| 54 | throw ConnectionFailed::upcast($e); | ||
| 55 | } | ||
| 56 | |||
| 57 | if (! $success) { | ||
| 58 | throw ConnectionFailed::new($connection); | ||
| 59 | } | ||
| 60 | |||
| 61 | foreach ($this->compilePostInitializers($params) as $initializer) { | ||
| 62 | $initializer->initialize($connection); | ||
| 63 | } | ||
| 64 | |||
| 65 | return new Connection($connection); | ||
| 66 | } | ||
| 67 | |||
| 68 | /** | ||
| 69 | * @param array<string, mixed> $params | ||
| 70 | * | ||
| 71 | * @return Generator<int, Initializer> | ||
| 72 | */ | ||
| 73 | private function compilePreInitializers( | ||
| 74 | #[SensitiveParameter] | ||
| 75 | array $params, | ||
| 76 | ): Generator { | ||
| 77 | unset($params['driverOptions'][Connection::OPTION_FLAGS]); | ||
| 78 | |||
| 79 | if (isset($params['driverOptions']) && $params['driverOptions'] !== []) { | ||
| 80 | yield new Options($params['driverOptions']); | ||
| 81 | } | ||
| 82 | |||
| 83 | if ( | ||
| 84 | ! isset($params['ssl_key']) && | ||
| 85 | ! isset($params['ssl_cert']) && | ||
| 86 | ! isset($params['ssl_ca']) && | ||
| 87 | ! isset($params['ssl_capath']) && | ||
| 88 | ! isset($params['ssl_cipher']) | ||
| 89 | ) { | ||
| 90 | return; | ||
| 91 | } | ||
| 92 | |||
| 93 | yield new Secure( | ||
| 94 | $params['ssl_key'] ?? '', | ||
| 95 | $params['ssl_cert'] ?? '', | ||
| 96 | $params['ssl_ca'] ?? '', | ||
| 97 | $params['ssl_capath'] ?? '', | ||
| 98 | $params['ssl_cipher'] ?? '', | ||
| 99 | ); | ||
| 100 | } | ||
| 101 | |||
| 102 | /** | ||
| 103 | * @param array<string, mixed> $params | ||
| 104 | * | ||
| 105 | * @return Generator<int, Initializer> | ||
| 106 | */ | ||
| 107 | private function compilePostInitializers( | ||
| 108 | #[SensitiveParameter] | ||
| 109 | array $params, | ||
| 110 | ): Generator { | ||
| 111 | if (! isset($params['charset'])) { | ||
| 112 | return; | ||
| 113 | } | ||
| 114 | |||
| 115 | yield new Charset($params['charset']); | ||
| 116 | } | ||
| 117 | } | ||
