summaryrefslogtreecommitdiff
path: root/vendor/doctrine/dbal/src/Portability/Driver.php
diff options
context:
space:
mode:
Diffstat (limited to 'vendor/doctrine/dbal/src/Portability/Driver.php')
-rw-r--r--vendor/doctrine/dbal/src/Portability/Driver.php69
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
3declare(strict_types=1);
4
5namespace Doctrine\DBAL\Portability;
6
7use Doctrine\DBAL\ColumnCase;
8use Doctrine\DBAL\Driver as DriverInterface;
9use Doctrine\DBAL\Driver\Connection as ConnectionInterface;
10use Doctrine\DBAL\Driver\Middleware\AbstractDriverMiddleware;
11use PDO;
12use SensitiveParameter;
13
14use const CASE_LOWER;
15use const CASE_UPPER;
16
17final 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}