Subversion-Projekte lars-tiefland.laravel_shop

Revision

Zur aktuellen Revision | Details | 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', '>=')) {
44
                return new MySQL80Platform();
45
            }
46
 
47
            if (version_compare($oracleMysqlVersion, '5.7.9', '>=')) {
48
                return new MySQL57Platform();
49
            }
50
        }
51
 
52
        Deprecation::trigger(
53
            'doctrine/dbal',
54
            'https://github.com/doctrine/dbal/pull/5060',
55
            'MySQL 5.6 support is deprecated and will be removed in DBAL 4.'
56
                . ' Consider upgrading to MySQL 5.7 or later.',
57
        );
58
 
59
        return $this->getDatabasePlatform();
60
    }
61
 
62
    /**
63
     * Get a normalized 'version number' from the server string
64
     * returned by Oracle MySQL servers.
65
     *
66
     * @param string $versionString Version string returned by the driver, i.e. '5.7.10'
67
     *
68
     * @throws Exception
69
     */
70
    private function getOracleMysqlVersionNumber(string $versionString): string
71
    {
72
        if (
73
            preg_match(
74
                '/^(?P<major>\d+)(?:\.(?P<minor>\d+)(?:\.(?P<patch>\d+))?)?/',
75
                $versionString,
76
                $versionParts,
77
            ) === 0
78
        ) {
79
            throw Exception::invalidPlatformVersionSpecified(
80
                $versionString,
81
                '<major_version>.<minor_version>.<patch_version>',
82
            );
83
        }
84
 
85
        $majorVersion = $versionParts['major'];
86
        $minorVersion = $versionParts['minor'] ?? 0;
87
        $patchVersion = $versionParts['patch'] ?? null;
88
 
89
        if ($majorVersion === '5' && $minorVersion === '7') {
90
            $patchVersion ??= '9';
91
        }
92
 
93
        return $majorVersion . '.' . $minorVersion . '.' . $patchVersion;
94
    }
95
 
96
    /**
97
     * Detect MariaDB server version, including hack for some mariadb distributions
98
     * that starts with the prefix '5.5.5-'
99
     *
100
     * @param string $versionString Version string as returned by mariadb server, i.e. '5.5.5-Mariadb-10.0.8-xenial'
101
     *
102
     * @throws Exception
103
     */
104
    private function getMariaDbMysqlVersionNumber(string $versionString): string
105
    {
106
        if (
107
            preg_match(
108
                '/^(?:5\.5\.5-)?(mariadb-)?(?P<major>\d+)\.(?P<minor>\d+)\.(?P<patch>\d+)/i',
109
                $versionString,
110
                $versionParts,
111
            ) === 0
112
        ) {
113
            throw Exception::invalidPlatformVersionSpecified(
114
                $versionString,
115
                '^(?:5\.5\.5-)?(mariadb-)?<major_version>.<minor_version>.<patch_version>',
116
            );
117
        }
118
 
119
        return $versionParts['major'] . '.' . $versionParts['minor'] . '.' . $versionParts['patch'];
120
    }
121
 
122
    /**
123
     * {@inheritdoc}
124
     *
125
     * @return AbstractMySQLPlatform
126
     */
127
    public function getDatabasePlatform()
128
    {
129
        return new MySQLPlatform();
130
    }
131
 
132
    /**
133
     * {@inheritdoc}
134
     *
135
     * @deprecated Use {@link AbstractMySQLPlatform::createSchemaManager()} instead.
136
     *
137
     * @return MySQLSchemaManager
138
     */
139
    public function getSchemaManager(Connection $conn, AbstractPlatform $platform)
140
    {
141
        Deprecation::triggerIfCalledFromOutside(
142
            'doctrine/dbal',
143
            'https://github.com/doctrine/dbal/pull/5458',
144
            'AbstractMySQLDriver::getSchemaManager() is deprecated.'
145
                . ' Use MySQLPlatform::createSchemaManager() instead.',
146
        );
147
 
148
        assert($platform instanceof AbstractMySQLPlatform);
149
 
150
        return new MySQLSchemaManager($conn, $platform);
151
    }
152
 
153
    public function getExceptionConverter(): ExceptionConverter
154
    {
155
        return new MySQL\ExceptionConverter();
156
    }
157
}