Connection.php
2 years ago
Converter.php
2 years ago
Driver.php
2 years ago
Middleware.php
2 years ago
OptimizeFlags.php
2 years ago
Result.php
2 years ago
Statement.php
2 years ago
index.php
2 years ago
Driver.php
49 lines
| 1 | <?php |
| 2 | namespace MailPoetVendor\Doctrine\DBAL\Portability; |
| 3 | if (!defined('ABSPATH')) exit; |
| 4 | use MailPoetVendor\Doctrine\DBAL\ColumnCase; |
| 5 | use MailPoetVendor\Doctrine\DBAL\Driver as DriverInterface; |
| 6 | use MailPoetVendor\Doctrine\DBAL\Driver\Middleware\AbstractDriverMiddleware; |
| 7 | use LogicException; |
| 8 | use PDO; |
| 9 | use MailPoetVendor\SensitiveParameter; |
| 10 | use function method_exists; |
| 11 | final class Driver extends AbstractDriverMiddleware |
| 12 | { |
| 13 | private int $mode; |
| 14 | private int $case; |
| 15 | public function __construct(DriverInterface $driver, int $mode, int $case) |
| 16 | { |
| 17 | parent::__construct($driver); |
| 18 | $this->mode = $mode; |
| 19 | $this->case = $case; |
| 20 | } |
| 21 | public function connect( array $params) |
| 22 | { |
| 23 | $connection = parent::connect($params); |
| 24 | $portability = (new OptimizeFlags())($this->getDatabasePlatform(), $this->mode); |
| 25 | $case = null; |
| 26 | if ($this->case !== 0 && ($portability & Connection::PORTABILITY_FIX_CASE) !== 0) { |
| 27 | $nativeConnection = null; |
| 28 | if (method_exists($connection, 'getNativeConnection')) { |
| 29 | try { |
| 30 | $nativeConnection = $connection->getNativeConnection(); |
| 31 | } catch (LogicException $e) { |
| 32 | } |
| 33 | } |
| 34 | if ($nativeConnection instanceof PDO) { |
| 35 | $portability &= ~Connection::PORTABILITY_FIX_CASE; |
| 36 | $nativeConnection->setAttribute(PDO::ATTR_CASE, $this->case === ColumnCase::LOWER ? PDO::CASE_LOWER : PDO::CASE_UPPER); |
| 37 | } else { |
| 38 | $case = $this->case === ColumnCase::LOWER ? Converter::CASE_LOWER : Converter::CASE_UPPER; |
| 39 | } |
| 40 | } |
| 41 | $convertEmptyStringToNull = ($portability & Connection::PORTABILITY_EMPTY_TO_NULL) !== 0; |
| 42 | $rightTrimString = ($portability & Connection::PORTABILITY_RTRIM) !== 0; |
| 43 | if (!$convertEmptyStringToNull && !$rightTrimString && $case === null) { |
| 44 | return $connection; |
| 45 | } |
| 46 | return new Connection($connection, new Converter($convertEmptyStringToNull, $rightTrimString, $case)); |
| 47 | } |
| 48 | } |
| 49 |