AbstractPostgreSQLDriver.php 1.9 KB
Newer Older
1 2 3 4
<?php

namespace Doctrine\DBAL\Driver;

5
use Doctrine\DBAL\Connection;
6
use Doctrine\DBAL\DBALException;
7 8
use Doctrine\DBAL\Driver\API\ExceptionConverter;
use Doctrine\DBAL\Driver\API\PostgreSQL;
9
use Doctrine\DBAL\Platforms\AbstractPlatform;
10
use Doctrine\DBAL\Platforms\PostgreSQL100Platform;
11
use Doctrine\DBAL\Platforms\PostgreSQL94Platform;
12 13
use Doctrine\DBAL\Schema\PostgreSqlSchemaManager;
use Doctrine\DBAL\VersionAwarePlatformDriver;
14

15 16
use function preg_match;
use function version_compare;
17 18

/**
19
 * Abstract base implementation of the {@link Driver} interface for PostgreSQL based drivers.
20
 */
21
abstract class AbstractPostgreSQLDriver implements VersionAwarePlatformDriver
22 23 24 25 26 27
{
    /**
     * {@inheritdoc}
     */
    public function createDatabasePlatformForVersion($version)
    {
28
        if (preg_match('/^(?P<major>\d+)(?:\.(?P<minor>\d+)(?:\.(?P<patch>\d+))?)?/', $version, $versionParts) === 0) {
29 30 31 32 33 34 35
            throw DBALException::invalidPlatformVersionSpecified(
                $version,
                '<major_version>.<minor_version>.<patch_version>'
            );
        }

        $majorVersion = $versionParts['major'];
36 37
        $minorVersion = $versionParts['minor'] ?? 0;
        $patchVersion = $versionParts['patch'] ?? 0;
38 39
        $version      = $majorVersion . '.' . $minorVersion . '.' . $patchVersion;

40 41
        if (version_compare($version, '10.0', '>=')) {
            return new PostgreSQL100Platform();
42
        }
43

44
        return new PostgreSQL94Platform();
45 46 47 48 49 50 51
    }

    /**
     * {@inheritdoc}
     */
    public function getDatabasePlatform()
    {
52
        return new PostgreSQL94Platform();
53 54 55 56 57
    }

    /**
     * {@inheritdoc}
     */
58
    public function getSchemaManager(Connection $conn, AbstractPlatform $platform)
59
    {
60
        return new PostgreSqlSchemaManager($conn, $platform);
61
    }
62 63 64 65 66

    public function getExceptionConverter(): ExceptionConverter
    {
        return new PostgreSQL\ExceptionConverter();
    }
67
}