| 148 |
lars |
1 |
<?php
|
|
|
2 |
|
|
|
3 |
namespace Doctrine\DBAL\Portability;
|
|
|
4 |
|
|
|
5 |
use Doctrine\DBAL\ColumnCase;
|
|
|
6 |
use Doctrine\DBAL\Driver as DriverInterface;
|
|
|
7 |
use Doctrine\DBAL\Driver\Middleware\AbstractDriverMiddleware;
|
|
|
8 |
use LogicException;
|
|
|
9 |
use PDO;
|
|
|
10 |
|
|
|
11 |
use function method_exists;
|
|
|
12 |
|
|
|
13 |
use const CASE_LOWER;
|
|
|
14 |
use const CASE_UPPER;
|
|
|
15 |
|
|
|
16 |
final class Driver extends AbstractDriverMiddleware
|
|
|
17 |
{
|
|
|
18 |
private int $mode;
|
|
|
19 |
|
|
|
20 |
private int $case;
|
|
|
21 |
|
|
|
22 |
public function __construct(DriverInterface $driver, int $mode, int $case)
|
|
|
23 |
{
|
|
|
24 |
parent::__construct($driver);
|
|
|
25 |
|
|
|
26 |
$this->mode = $mode;
|
|
|
27 |
$this->case = $case;
|
|
|
28 |
}
|
|
|
29 |
|
|
|
30 |
/**
|
|
|
31 |
* {@inheritDoc}
|
|
|
32 |
*/
|
|
|
33 |
public function connect(array $params)
|
|
|
34 |
{
|
|
|
35 |
$connection = parent::connect($params);
|
|
|
36 |
|
|
|
37 |
$portability = (new OptimizeFlags())(
|
|
|
38 |
$this->getDatabasePlatform(),
|
|
|
39 |
$this->mode,
|
|
|
40 |
);
|
|
|
41 |
|
|
|
42 |
$case = null;
|
|
|
43 |
|
|
|
44 |
if ($this->case !== 0 && ($portability & Connection::PORTABILITY_FIX_CASE) !== 0) {
|
|
|
45 |
$nativeConnection = null;
|
|
|
46 |
if (method_exists($connection, 'getNativeConnection')) {
|
|
|
47 |
try {
|
|
|
48 |
$nativeConnection = $connection->getNativeConnection();
|
|
|
49 |
} catch (LogicException $e) {
|
|
|
50 |
}
|
|
|
51 |
}
|
|
|
52 |
|
|
|
53 |
if ($nativeConnection instanceof PDO) {
|
|
|
54 |
$portability &= ~Connection::PORTABILITY_FIX_CASE;
|
|
|
55 |
$nativeConnection->setAttribute(PDO::ATTR_CASE, $this->case);
|
|
|
56 |
} else {
|
|
|
57 |
$case = $this->case === ColumnCase::LOWER ? CASE_LOWER : CASE_UPPER;
|
|
|
58 |
}
|
|
|
59 |
}
|
|
|
60 |
|
|
|
61 |
$convertEmptyStringToNull = ($portability & Connection::PORTABILITY_EMPTY_TO_NULL) !== 0;
|
|
|
62 |
$rightTrimString = ($portability & Connection::PORTABILITY_RTRIM) !== 0;
|
|
|
63 |
|
|
|
64 |
if (! $convertEmptyStringToNull && ! $rightTrimString && $case === null) {
|
|
|
65 |
return $connection;
|
|
|
66 |
}
|
|
|
67 |
|
|
|
68 |
return new Connection(
|
|
|
69 |
$connection,
|
|
|
70 |
new Converter($convertEmptyStringToNull, $rightTrimString, $case),
|
|
|
71 |
);
|
|
|
72 |
}
|
|
|
73 |
}
|