|
7 | 7 | use Doctrine\DBAL\Driver;
|
8 | 8 | use Doctrine\DBAL\Driver\API\ExceptionConverter as ExceptionConverterInterface;
|
9 | 9 | use Doctrine\DBAL\Driver\API\PostgreSQL\ExceptionConverter;
|
| 10 | +use Doctrine\DBAL\Platforms\Exception\InvalidPlatformVersion; |
| 11 | +use Doctrine\DBAL\Platforms\PostgreSQL120Platform; |
10 | 12 | use Doctrine\DBAL\Platforms\PostgreSQLPlatform;
|
11 | 13 | use Doctrine\DBAL\ServerVersionProvider;
|
12 | 14 |
|
| 15 | +use function preg_match; |
| 16 | +use function version_compare; |
| 17 | + |
13 | 18 | /**
|
14 | 19 | * Abstract base implementation of the {@see Driver} interface for PostgreSQL based drivers.
|
15 | 20 | */
|
16 | 21 | abstract class AbstractPostgreSQLDriver implements Driver
|
17 | 22 | {
|
18 | 23 | public function getDatabasePlatform(ServerVersionProvider $versionProvider): PostgreSQLPlatform
|
19 | 24 | {
|
| 25 | + $version = $versionProvider->getServerVersion(); |
| 26 | + |
| 27 | + if (preg_match('/^(?P<major>\d+)(?:\.(?P<minor>\d+)(?:\.(?P<patch>\d+))?)?/', $version, $versionParts) === 0) { |
| 28 | + throw InvalidPlatformVersion::new( |
| 29 | + $version, |
| 30 | + '<major_version>.<minor_version>.<patch_version>', |
| 31 | + ); |
| 32 | + } |
| 33 | + |
| 34 | + $majorVersion = $versionParts['major']; |
| 35 | + $minorVersion = $versionParts['minor'] ?? 0; |
| 36 | + $patchVersion = $versionParts['patch'] ?? 0; |
| 37 | + $version = $majorVersion . '.' . $minorVersion . '.' . $patchVersion; |
| 38 | + |
| 39 | + if (version_compare($version, '12.0', '>=')) { |
| 40 | + return new PostgreSQL120Platform(); |
| 41 | + } |
| 42 | + |
20 | 43 | return new PostgreSQLPlatform();
|
21 | 44 | }
|
22 | 45 |
|
|
0 commit comments