1. Go to this page and download the library: Download jsor/doctrine-postgis library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
jsor / doctrine-postgis example snippets
use Doctrine\DBAL\Configuration;
use Doctrine\DBAL\Connection;
use Doctrine\DBAL\Driver\PgSQL\Driver;
use Jsor\Doctrine\PostGIS\Driver\Middleware;
use Jsor\Doctrine\PostGIS\Event\ORMSchemaEventListener;
use Jsor\Doctrine\PostGIS\Schema\SchemaManagerFactory;
$params = [
// your connection parameters …
];
$config = new Configuration();
$config->setMiddlewares([new Middleware]);
$config->setSchemaManagerFactory(new SchemaManagerFactory());
$connection = new Connection($params, new Driver(), $config);
use Doctrine\ORM\Tools\ToolEvents;
use Jsor\Doctrine\PostGIS\Event\ORMSchemaEventListener;
$entityManager->getEventManager()->addEventListener(ToolEvents::postGenerateSchemaTable, new ORMSchemaEventListener());
use Doctrine\ORM\Mapping as ORM;
use Jsor\Doctrine\PostGIS\Types\PostGISType;
#[ORM\Entity]
class MyEntity
{
#[ORM\Column(type: PostGISType::GEOMETRY)]
private string $geometry;
#[ORM\Column(type: PostGISType::GEOGRAPHY)]
private string $geography;
}
use Doctrine\ORM\Mapping as ORM;
use Jsor\Doctrine\PostGIS\Types\PostGISType;
#[ORM\Entity]
class MyEntity
{
#[ORM\Column(
type: PostGISType::GEOMETRY,
options: ['geometry_type' => 'POINT'],
)]
public string $point;
#[ORM\Column(
type: PostGISType::GEOMETRY,
options: ['geometry_type' => 'POINTZM'],
)]
public string $point4D;
#[ORM\Column(
type: PostGISType::GEOMETRY,
options: ['geometry_type' => 'POINT', 'srid' => 3785],
)]
public string $pointWithSRID;
public function __construct(
string $point,
string $point4D,
string $pointWithSRID,
) {
$this->point = $point;
$this->point4D = $point4D;
$this->pointWithSRID = $pointWithSRID;
}
}