Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot use object of type Doctrine\Common\Lexer\Token as array #229

Open
marcoslp010 opened this issue Oct 24, 2024 · 0 comments
Open

Cannot use object of type Doctrine\Common\Lexer\Token as array #229

marcoslp010 opened this issue Oct 24, 2024 · 0 comments

Comments

@marcoslp010
Copy link

marcoslp010 commented Oct 24, 2024

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;
    }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant