From 53cbe426a71b797f775f824781850b3d561aae4d Mon Sep 17 00:00:00 2001 From: Nickolas Lyzhov Date: Wed, 2 Aug 2023 10:54:16 +0300 Subject: [PATCH 1/3] [HOTFIX] --- .../DBAL/Types/AbstractSpatialType.php | 27 ++++++++++++------- 1 file changed, 18 insertions(+), 9 deletions(-) diff --git a/lib/CrEOF/Spatial/DBAL/Types/AbstractSpatialType.php b/lib/CrEOF/Spatial/DBAL/Types/AbstractSpatialType.php index fd36d15b..c239dac0 100644 --- a/lib/CrEOF/Spatial/DBAL/Types/AbstractSpatialType.php +++ b/lib/CrEOF/Spatial/DBAL/Types/AbstractSpatialType.php @@ -23,12 +23,18 @@ namespace CrEOF\Spatial\DBAL\Types; +use CrEOF\Spatial\DBAL\Platform\MySql; +use CrEOF\Spatial\DBAL\Platform\MySql80; +use CrEOF\Spatial\DBAL\Platform\PlatformInterface; +use CrEOF\Spatial\DBAL\Platform\PostgreSql; use CrEOF\Spatial\Exception\InvalidValueException; use CrEOF\Spatial\Exception\UnsupportedPlatformException; -use CrEOF\Spatial\DBAL\Platform\PlatformInterface; use CrEOF\Spatial\PHP\Types\Geography\GeographyInterface; use CrEOF\Spatial\PHP\Types\Geometry\GeometryInterface; use Doctrine\DBAL\Platforms\AbstractPlatform; +use Doctrine\DBAL\Platforms\MySQL80Platform; +use Doctrine\DBAL\Platforms\MySQLPlatform; +use Doctrine\DBAL\Platforms\PostgreSQLPlatform; use Doctrine\DBAL\Types\Type; /** @@ -39,9 +45,6 @@ */ abstract class AbstractSpatialType extends Type { - const PLATFORM_MYSQL = 'MySql'; - const PLATFORM_POSTGRESQL = 'PostgreSql'; - /** * @return string */ @@ -201,13 +204,19 @@ public function requiresSQLCommentHint(AbstractPlatform $platform) */ private function getSpatialPlatform(AbstractPlatform $platform) { - $const = sprintf('self::PLATFORM_%s', strtoupper($platform->getName())); - - if (! defined($const)) { - throw new UnsupportedPlatformException(sprintf('DBAL platform "%s" is not currently supported.', $platform->getName())); + $class = null; + + if ($platform instanceof \Doctrine\DBAL\Platforms\MySQL80Platform) { + $class = MySql80::class; + } elseif ($platform instanceof \Doctrine\DBAL\Platforms\MySQLPlatform) { + $class = MySql::class; + } elseif ($platform instanceof \Doctrine\DBAL\Platforms\PostgreSQLPlatform) { + $class = PostgreSql::class; } - $class = sprintf('CrEOF\Spatial\DBAL\Platform\%s', constant($const)); + if (!$class) { + throw new UnsupportedPlatformException(sprintf('DBAL platform "%s" is not currently supported.', get_class($platform))); + } return new $class; } From b46b5c52d770e147693e71fc65ad5d1a0cace9ca Mon Sep 17 00:00:00 2001 From: Nickolas Lyzhov Date: Wed, 2 Aug 2023 10:55:56 +0300 Subject: [PATCH 2/3] [FEATURE] MySQL80 --- lib/CrEOF/Spatial/DBAL/Platform/MySql80.php | 58 +++++++++++++++++++++ 1 file changed, 58 insertions(+) create mode 100644 lib/CrEOF/Spatial/DBAL/Platform/MySql80.php diff --git a/lib/CrEOF/Spatial/DBAL/Platform/MySql80.php b/lib/CrEOF/Spatial/DBAL/Platform/MySql80.php new file mode 100644 index 00000000..a5bc7ead --- /dev/null +++ b/lib/CrEOF/Spatial/DBAL/Platform/MySql80.php @@ -0,0 +1,58 @@ + + * @license http://dlambert.mit-license.org MIT + */ +class MySql80 extends MySql +{ + /** + * @param AbstractSpatialType $type + * @param string $sqlExpr + * + * @return string + */ + public function convertToPHPValueSQL(AbstractSpatialType $type, $sqlExpr) + { + return sprintf('ST_AsBinary(%s)', $sqlExpr); + } + + /** + * @param AbstractSpatialType $type + * @param string $sqlExpr + * + * @return string + */ + public function convertToDatabaseValueSQL(AbstractSpatialType $type, $sqlExpr) + { + return sprintf('ST_GeomFromText(%s)', $sqlExpr); + } +} From 843ddde16e8a4cfdb98d59002848c77ee2905fc4 Mon Sep 17 00:00:00 2001 From: Nickolas Lyzhov Date: Wed, 2 Aug 2023 11:15:12 +0300 Subject: [PATCH 3/3] [REFACTOR] Classes --- lib/CrEOF/Spatial/DBAL/Platform/MySql80.php | 1 - lib/CrEOF/Spatial/DBAL/Types/AbstractSpatialType.php | 6 +++--- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/lib/CrEOF/Spatial/DBAL/Platform/MySql80.php b/lib/CrEOF/Spatial/DBAL/Platform/MySql80.php index a5bc7ead..dfd12ff4 100644 --- a/lib/CrEOF/Spatial/DBAL/Platform/MySql80.php +++ b/lib/CrEOF/Spatial/DBAL/Platform/MySql80.php @@ -24,7 +24,6 @@ namespace CrEOF\Spatial\DBAL\Platform; use CrEOF\Spatial\DBAL\Types\AbstractSpatialType; -use CrEOF\Spatial\PHP\Types\Geography\GeographyInterface; /** * MySql spatial platform diff --git a/lib/CrEOF/Spatial/DBAL/Types/AbstractSpatialType.php b/lib/CrEOF/Spatial/DBAL/Types/AbstractSpatialType.php index c239dac0..8e642521 100644 --- a/lib/CrEOF/Spatial/DBAL/Types/AbstractSpatialType.php +++ b/lib/CrEOF/Spatial/DBAL/Types/AbstractSpatialType.php @@ -206,11 +206,11 @@ private function getSpatialPlatform(AbstractPlatform $platform) { $class = null; - if ($platform instanceof \Doctrine\DBAL\Platforms\MySQL80Platform) { + if ($platform instanceof MySQL80Platform) { $class = MySql80::class; - } elseif ($platform instanceof \Doctrine\DBAL\Platforms\MySQLPlatform) { + } elseif ($platform instanceof MySQLPlatform) { $class = MySql::class; - } elseif ($platform instanceof \Doctrine\DBAL\Platforms\PostgreSQLPlatform) { + } elseif ($platform instanceof PostgreSQLPlatform) { $class = PostgreSql::class; }