brick / geo-doctrine Goto Github PK
View Code? Open in Web Editor NEWDoctrine types & functions for brick/geo
License: MIT License
Doctrine types & functions for brick/geo
License: MIT License
I was unable to use the library at all since I was unable to get the mapping to work due to this exception:
The annotation "@noproxy" in method Brick\Geo\Geometry::SRID() was never imported. Did you maybe forget to add a "use" statement for this annotation?
In fact I was lost due to the lack of documentation and ended up abandoning this promising package.
Is there someone who managed to get this package to work?
I'm trying to use PointType in my symfony project, but I don't know how to use on my controller. Can you help me or give an example please?
Here my config/packages/doctrine.yaml
config:
doctrine:
dbal:
types:
Point: Brick\Geo\Doctrine\Types\PointType
mapping_types:
Point: Point
Then in my Entity:
use Brick\Geo\Doctrine\Types\PointType as Point;
#[ORM\Entity(repositoryClass: UserRepository::class)]
#[ORM\Table(name: '`user`')]
class User
{
#[ORM\Column(type: 'Point', nullable:true)]
private $latlong;
public function getLatlong(): ?Point
{
return $this->latlong;
}
public function setLatlong(Point $latlong): self
{
$this->latlong = $latlong;
return $this;
}
And, how can I use $user->setLatlong();
inside of my controller?
public function myfunction(Request $request, EntityManagerInterface $entityManager): Response
{
$user = new user();
$pointType = //how can create PointType
$user->setLatlong($pointType);
$entityManager->persist($user);
$entityManager->flush();
return $this->render('mytemplate.html.twig');
}
Thanks
@BenMorel hello, can you please add DoctrineEngine
to the lib?
i am using this one, based on PDOEngine
. it works, but perhaps needs your check if it it's all correct.
one big advantage of using doctrine over pdo is that doctrine queries get logged.
so you can inspect all the actual queries made, e.g. in symfony profiler.
<?php declare(strict_types=1);
namespace App\Geo\Doctrine;
use Brick\Geo\Engine\DatabaseEngine;
use Brick\Geo\Engine\GeometryParameter;
use Brick\Geo\Exception\GeometryEngineException;
use Doctrine\DBAL\Connection;
use Doctrine\DBAL\Driver\Exception as DBALException;
use Doctrine\DBAL\ParameterType;
use Doctrine\DBAL\Platforms\MySQLPlatform;
use Doctrine\DBAL\Platforms\PostgreSQLPlatform;
use Doctrine\DBAL\Statement;
use Doctrine\ORM\EntityManagerInterface;
class DoctrineEngine extends DatabaseEngine
{
/** @var Statement[] */
private array $statements = [];
public function __construct(
private readonly EntityManagerInterface $em,
bool $useProxy = true,
) {
parent::__construct($useProxy);
}
protected function getDBAL(): Connection
{
return $this->em->getConnection();
}
protected function executeQuery(string $query, array $parameters): array
{
try {
if (!isset($this->statements[$query])) {
$this->statements[$query] = $this->getDBAL()->prepare($query);
}
$statement = $this->statements[$query];
$index = 1;
foreach ($parameters as $parameter) {
if ($parameter instanceof GeometryParameter) {
$statement->bindValue($index++, $parameter->data, $parameter->isBinary ? ParameterType::LARGE_OBJECT : ParameterType::STRING);
$statement->bindValue($index++, $parameter->srid, ParameterType::INTEGER);
} else {
if (is_int($parameter)) {
$type = ParameterType::INTEGER;
} else {
$type = ParameterType::STRING;
}
$statement->bindValue($index++, $parameter, $type);
}
}
$result = $statement->getWrappedStatement()->execute();
$result = $result->fetchNumeric();
} catch (DBALException $e) {
$errorClass = substr((string) $e->getSQLState(), 0, 2);
// 42XXX = syntax error or access rule violation; reported on undefined function.
// 22XXX = data exception; reported by MySQL 5.7 on unsupported geometry.
if ('42' === $errorClass || '22' === $errorClass) {
throw GeometryEngineException::operationNotSupportedByEngine($e);
}
throw $e;
} catch (\Throwable $e) {
$errorClass = substr((string) $e->getCode(), 0, 2);
// 42XXX = syntax error or access rule violation; reported on undefined function.
// 22XXX = data exception; reported by MySQL 5.7 on unsupported geometry.
if ('42' === $errorClass || '22' === $errorClass) {
throw GeometryEngineException::operationNotSupportedByEngine($e);
}
throw $e;
}
assert(false !== $result);
return $result;
}
protected function getGeomFromWKBSyntax(): string
{
if ($this->isMySQL()) {
return 'ST_GeomFromWKB(BINARY ?, ?)';
}
return parent::getGeomFromWKBSyntax();
}
protected function getParameterPlaceholder(string|float|int $parameter): string
{
if ($this->isPostgreSQL()) {
if (is_int($parameter)) {
// https://stackoverflow.com/q/66625661/759866
// https://externals.io/message/113521
return 'CAST (? AS INTEGER)';
}
}
return parent::getParameterPlaceholder($parameter);
}
protected function isMySQL(): bool
{
return $this->getDBAL()->getDatabasePlatform() instanceof MySQLPlatform;
}
protected function isPostgreSQL(): bool
{
return $this->getDBAL()->getDatabasePlatform() instanceof PostgreSQLPlatform;
}
}
Please how do I resolve this Issue?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.