Open
Description
Error:
Cannot use object of type Doctrine\Common\Lexer\Token as array
at \vendor\creof\geo-parser\lib\CrEOF\Geo\String\Parser.php:471
I created the point type to be used in MySQL 8.0
<?php
namespace App\DBAL;
use CrEOF\Spatial\PHP\Types\Geometry\Point;
use Doctrine\DBAL\Platforms\AbstractPlatform;
use Doctrine\DBAL\Types\Type;
class PointType extends Type
{
const POINT = 'point';
public function getSQLDeclaration(array $fieldDeclaration, AbstractPlatform $platform): string
{
return 'POINT';
}
public function convertToPHPValue($value, AbstractPlatform $platform)
{
if (empty($value)) {
return null;
}
$wkb = unpack('H*', $value);
$hex = $wkb[1];
return $this->convertWKBToPoint($hex);
}
private function convertWKBToPoint($hex)
{
$binary = hex2bin($hex);
$srid = unpack('N', substr($binary, 0, 4))[1];
$endian = unpack('C', $binary[4])[1];
$format = $endian === 1 ? 'V' : 'N';
if ($format === 'V') {
$coords = unpack('dX/dY', substr($binary, 9));
} else {
$coords = unpack('dX/dY', substr($binary, 9));
}
return new Point($coords['X'] , $coords['Y']);
}
public function convertToDatabaseValue($value, AbstractPlatform $platform)
{
if (empty($value)) {
return null;
}
return sprintf('POINT(%F %F)', $value->getLatitude(), $value->getLongitude());
}
public function getName(): string
{
return self::POINT;
}
}
Metadata
Metadata
Assignees
Labels
No labels