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/Portability/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/Portability/Driver.php')
| -rw-r--r-- | vendor/doctrine/dbal/src/Portability/Driver.php | 69 |
1 files changed, 69 insertions, 0 deletions
diff --git a/vendor/doctrine/dbal/src/Portability/Driver.php b/vendor/doctrine/dbal/src/Portability/Driver.php new file mode 100644 index 0000000..bb67c25 --- /dev/null +++ b/vendor/doctrine/dbal/src/Portability/Driver.php | |||
| @@ -0,0 +1,69 @@ | |||
| 1 | <?php | ||
| 2 | |||
| 3 | declare(strict_types=1); | ||
| 4 | |||
| 5 | namespace Doctrine\DBAL\Portability; | ||
| 6 | |||
| 7 | use Doctrine\DBAL\ColumnCase; | ||
| 8 | use Doctrine\DBAL\Driver as DriverInterface; | ||
| 9 | use Doctrine\DBAL\Driver\Connection as ConnectionInterface; | ||
| 10 | use Doctrine\DBAL\Driver\Middleware\AbstractDriverMiddleware; | ||
| 11 | use PDO; | ||
| 12 | use SensitiveParameter; | ||
| 13 | |||
| 14 | use const CASE_LOWER; | ||
| 15 | use const CASE_UPPER; | ||
| 16 | |||
| 17 | final class Driver extends AbstractDriverMiddleware | ||
| 18 | { | ||
| 19 | public function __construct( | ||
| 20 | DriverInterface $driver, | ||
| 21 | private readonly int $mode, | ||
| 22 | private readonly ?ColumnCase $case, | ||
| 23 | ) { | ||
| 24 | parent::__construct($driver); | ||
| 25 | } | ||
| 26 | |||
| 27 | /** | ||
| 28 | * {@inheritDoc} | ||
| 29 | */ | ||
| 30 | public function connect( | ||
| 31 | #[SensitiveParameter] | ||
| 32 | array $params, | ||
| 33 | ): ConnectionInterface { | ||
| 34 | $connection = parent::connect($params); | ||
| 35 | |||
| 36 | $portability = (new OptimizeFlags())( | ||
| 37 | $this->getDatabasePlatform($connection), | ||
| 38 | $this->mode, | ||
| 39 | ); | ||
| 40 | |||
| 41 | $case = null; | ||
| 42 | |||
| 43 | if ($this->case !== null && ($portability & Connection::PORTABILITY_FIX_CASE) !== 0) { | ||
| 44 | $nativeConnection = $connection->getNativeConnection(); | ||
| 45 | |||
| 46 | $case = match ($this->case) { | ||
| 47 | ColumnCase::LOWER => CASE_LOWER, | ||
| 48 | ColumnCase::UPPER => CASE_UPPER, | ||
| 49 | }; | ||
| 50 | |||
| 51 | if ($nativeConnection instanceof PDO) { | ||
| 52 | $portability &= ~Connection::PORTABILITY_FIX_CASE; | ||
| 53 | $nativeConnection->setAttribute(PDO::ATTR_CASE, $case); | ||
| 54 | } | ||
| 55 | } | ||
| 56 | |||
| 57 | $convertEmptyStringToNull = ($portability & Connection::PORTABILITY_EMPTY_TO_NULL) !== 0; | ||
| 58 | $rightTrimString = ($portability & Connection::PORTABILITY_RTRIM) !== 0; | ||
| 59 | |||
| 60 | if (! $convertEmptyStringToNull && ! $rightTrimString && $case === null) { | ||
| 61 | return $connection; | ||
| 62 | } | ||
| 63 | |||
| 64 | return new Connection( | ||
| 65 | $connection, | ||
| 66 | new Converter($convertEmptyStringToNull, $rightTrimString, $case), | ||
| 67 | ); | ||
| 68 | } | ||
| 69 | } | ||
