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\Driver;
4
 
5
use Doctrine\DBAL\Connection;
6
use Doctrine\DBAL\Driver\API\ExceptionConverter;
7
use Doctrine\DBAL\Driver\API\MySQL;
8
use Doctrine\DBAL\Exception;
9
use Doctrine\DBAL\Platforms\AbstractMySQLPlatform;
10
use Doctrine\DBAL\Platforms\AbstractPlatform;
11
use Doctrine\DBAL\Platforms\MariaDb1027Platform;
12
use Doctrine\DBAL\Platforms\MySQL57Platform;
13
use Doctrine\DBAL\Platforms\MySQL80Platform;
14
use Doctrine\DBAL\Platforms\MySQLPlatform;
15
use Doctrine\DBAL\Schema\MySQLSchemaManager;
16
use Doctrine\DBAL\VersionAwarePlatformDriver;
17
use Doctrine\Deprecations\Deprecation;
18
 
19
use function assert;
20
use function preg_match;
21
use function stripos;
22
use function version_compare;
23
 
24
/**
25
 * Abstract base implementation of the {@see Driver} interface for MySQL based drivers.
26
 */
27
abstract class AbstractMySQLDriver implements VersionAwarePlatformDriver
28
{
29
    /**
30
     * {@inheritdoc}
31
     *
32
     * @throws Exception
33
     */
34
    public function createDatabasePlatformForVersion($version)
35
    {
36
        $mariadb = stripos($version, 'mariadb') !== false;
37
        if ($mariadb && version_compare($this->getMariaDbMysqlVersionNumber($version), '10.2.7', '>=')) {
38
            return new MariaDb1027Platform();
39
        }
40
 
41
        if (! $mariadb) {
42
            $oracleMysqlVersion = $this->getOracleMysqlVersionNumber($version);
43
            if (version_compare($oracleMysqlVersion, '8', '>=')) {
621 lars 44
                if (! version_compare($version, '8.0.0', '>=')) {
45
                    Deprecation::trigger(
46
                        'doctrine/orm',
47
                        'https://github.com/doctrine/dbal/pull/5779',
48
                        'Version detection logic for MySQL will change in DBAL 4. '
49
                            . 'Please specify the version as the server reports it, e.g. "8.0.31" instead of "8".',
50
                    );
51
                }
52
 
148 lars 53
                return new MySQL80Platform();
54
            }
55
 
56
            if (version_compare($oracleMysqlVersion, '5.7.9', '>=')) {
621 lars 57
                if (! version_compare($version, '5.7.9', '>=')) {
58
                    Deprecation::trigger(
59
                        'doctrine/orm',
60
                        'https://github.com/doctrine/dbal/pull/5779',
61
                        'Version detection logic for MySQL will change in DBAL 4. '
62
                        . 'Please specify the version as the server reports it, e.g. "5.7.40" instead of "5.7".',
63
                    );
64
                }
65
 
148 lars 66
                return new MySQL57Platform();
67
            }
68
        }
69
 
70
        Deprecation::trigger(
71
            'doctrine/dbal',
72
            'https://github.com/doctrine/dbal/pull/5060',
73
            'MySQL 5.6 support is deprecated and will be removed in DBAL 4.'
74
                . ' Consider upgrading to MySQL 5.7 or later.',
75
        );
76
 
77
        return $this->getDatabasePlatform();
78
    }
79
 
80
    /**
81
     * Get a normalized 'version number' from the server string
82
     * returned by Oracle MySQL servers.
83
     *
84
     * @param string $versionString Version string returned by the driver, i.e. '5.7.10'
85
     *
86
     * @throws Exception
87
     */
88
    private function getOracleMysqlVersionNumber(string $versionString): string
89
    {
90
        if (
91
            preg_match(
92
                '/^(?P<major>\d+)(?:\.(?P<minor>\d+)(?:\.(?P<patch>\d+))?)?/',
93
                $versionString,
94
                $versionParts,
95
            ) === 0
96
        ) {
97
            throw Exception::invalidPlatformVersionSpecified(
98
                $versionString,
99
                '<major_version>.<minor_version>.<patch_version>',
100
            );
101
        }
102
 
103
        $majorVersion = $versionParts['major'];
104
        $minorVersion = $versionParts['minor'] ?? 0;
105
        $patchVersion = $versionParts['patch'] ?? null;
106
 
107
        if ($majorVersion === '5' && $minorVersion === '7') {
108
            $patchVersion ??= '9';
109
        }
110
 
111
        return $majorVersion . '.' . $minorVersion . '.' . $patchVersion;
112
    }
113
 
114
    /**
115
     * Detect MariaDB server version, including hack for some mariadb distributions
116
     * that starts with the prefix '5.5.5-'
117
     *
118
     * @param string $versionString Version string as returned by mariadb server, i.e. '5.5.5-Mariadb-10.0.8-xenial'
119
     *
120
     * @throws Exception
121
     */
122
    private function getMariaDbMysqlVersionNumber(string $versionString): string
123
    {
621 lars 124
        if (stripos($versionString, 'MariaDB') === 0) {
125
            Deprecation::trigger(
126
                'doctrine/orm',
127
                'https://github.com/doctrine/dbal/pull/5779',
128
                'Version detection logic for MySQL will change in DBAL 4. '
129
                    . 'Please specify the version as the server reports it, '
130
                    . 'e.g. "10.9.3-MariaDB" instead of "mariadb-10.9".',
131
            );
132
        }
133
 
148 lars 134
        if (
135
            preg_match(
136
                '/^(?:5\.5\.5-)?(mariadb-)?(?P<major>\d+)\.(?P<minor>\d+)\.(?P<patch>\d+)/i',
137
                $versionString,
138
                $versionParts,
139
            ) === 0
140
        ) {
141
            throw Exception::invalidPlatformVersionSpecified(
142
                $versionString,
143
                '^(?:5\.5\.5-)?(mariadb-)?<major_version>.<minor_version>.<patch_version>',
144
            );
145
        }
146
 
147
        return $versionParts['major'] . '.' . $versionParts['minor'] . '.' . $versionParts['patch'];
148
    }
149
 
150
    /**
151
     * {@inheritdoc}
152
     *
153
     * @return AbstractMySQLPlatform
154
     */
155
    public function getDatabasePlatform()
156
    {
157
        return new MySQLPlatform();
158
    }
159
 
160
    /**
161
     * {@inheritdoc}
162
     *
163
     * @deprecated Use {@link AbstractMySQLPlatform::createSchemaManager()} instead.
164
     *
165
     * @return MySQLSchemaManager
166
     */
167
    public function getSchemaManager(Connection $conn, AbstractPlatform $platform)
168
    {
169
        Deprecation::triggerIfCalledFromOutside(
170
            'doctrine/dbal',
171
            'https://github.com/doctrine/dbal/pull/5458',
172
            'AbstractMySQLDriver::getSchemaManager() is deprecated.'
173
                . ' Use MySQLPlatform::createSchemaManager() instead.',
174
        );
175
 
176
        assert($platform instanceof AbstractMySQLPlatform);
177
 
178
        return new MySQLSchemaManager($conn, $platform);
179
    }
180
 
181
    public function getExceptionConverter(): ExceptionConverter
182
    {
183
        return new MySQL\ExceptionConverter();
184
    }
185
}