Subversion-Projekte lars-tiefland.laravel_shop

Revision

Revision 148 | Details | Vergleich mit vorheriger | Letzte Änderung | Log anzeigen | RSS feed

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