Skip to content

Instantly share code, notes, and snippets.

@BenMorel
Created February 8, 2021 17:27
Show Gist options
  • Save BenMorel/d88fb4411a3c0fbd924df7def2d94074 to your computer and use it in GitHub Desktop.
Save BenMorel/d88fb4411a3c0fbd924df7def2d94074 to your computer and use it in GitHub Desktop.
{
"require": {
"doctrine/orm": "^2.8",
"brick/geo": "^0.4.0"
}
}
CREATE TABLE User (
id INT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY,
location POINT NOT NULL
);
INSERT INTO User (location) VALUES(ST_GeomFromText('POINT(1 1)'));
<?php
use Brick\Geo;
use Brick\Geo\Point;
use Doctrine\DBAL\DriverManager;
use Doctrine\DBAL\Types\Type;
use Doctrine\ORM\Configuration;
use Doctrine\ORM\EntityManager;
use Doctrine\ORM\Mapping as ORM;
use Foodbox\Configuration\AppConfiguration;
/**
* @ORM\Entity
*/
class User
{
/**
* @ORM\Id
* @ORM\Column(type="integer")
* @ORM\GeneratedValue
*/
private int $id;
/**
* @ORM\Column(type="Point")
*/
private Point $location;
}
require __DIR__ . '/vendor/autoload.php';
Type::addType('Point', Geo\Doctrine\Types\PointType::class);
$connection = DriverManager::getConnection([
'driver' => 'pdo_mysql',
'host' => 'localhost',
'user' => 'root',
'password' => '',
'dbname' => 'test'
]);
$config = new Configuration();
$config->setMetadataDriverImpl(
$config->newDefaultAnnotationDriver('.', false)
);
$config->setProxyDir(__DIR__);
$config->setProxyNamespace('App\Proxy');
$em = EntityManager::create($connection, $config);
var_dump($em->find(User::class, 1));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment