Skip to content

Commit

Permalink
Fix getWrappedConnection is deprecated (#222)
Browse files Browse the repository at this point in the history
* Fix getWrappedConnection is deprecated

* Fix phpstan
  • Loading branch information
dmitryuk authored Oct 8, 2024
1 parent 80855fc commit eefe736
Showing 1 changed file with 10 additions and 7 deletions.
17 changes: 10 additions & 7 deletions src/Provider/Doctrine/Persistence/Helper/PlatformHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,19 +28,14 @@ public static function isIndexLengthLimited(string $name, Connection $connection
}

$platform = $connection->getDatabasePlatform();
$version = self::getServerVersion($connection);

if (null === $version) {
return false;
}

// JSON wasn't supported on MariaDB before 10.2.7
// @see https://mariadb.com/kb/en/json-data-type/
if ($platform instanceof MariaDBPlatform) {
if ($platform instanceof MariaDBPlatform && ($version = self::getServerVersion($connection))) {
return version_compare(self::getMariaDbMysqlVersionNumber($version), '10.2.2', '<');
}

if ($platform instanceof MySQLPlatform) {
if ($platform instanceof MySQLPlatform && ($version = self::getServerVersion($connection))) {
return version_compare(self::getOracleMysqlVersionNumber($version), '5.7.7', '<');
}

Expand All @@ -49,6 +44,14 @@ public static function isIndexLengthLimited(string $name, Connection $connection

public static function getServerVersion(Connection $connection): ?string
{
if (method_exists($connection, 'getNativeConnection') && ($pdo = $connection->getNativeConnection()) instanceof \PDO) {
$version = $pdo->getAttribute(\PDO::ATTR_SERVER_VERSION);
if (\is_string($version)) {
return $version;
}

return null;
}
$reflected = new \ReflectionObject($connection);
if ($reflected->hasMethod('getServerVersion') && $reflected->getMethod('getServerVersion')->isPublic()) {
return $connection->getServerVersion();
Expand Down

0 comments on commit eefe736

Please sign in to comment.