Skip to content

Commit

Permalink
Replace annotation with attribute mappings
Browse files Browse the repository at this point in the history
  • Loading branch information
jsor committed Sep 7, 2021
1 parent acf2fe6 commit f4c81aa
Show file tree
Hide file tree
Showing 156 changed files with 1,027 additions and 1,056 deletions.
95 changes: 54 additions & 41 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -114,18 +114,17 @@ Once the event subscriber is registered, you can use the column types
to understand the difference between these two types).

```php
/** @Entity */
use Doctrine\ORM\Mapping as ORM;
use Jsor\Doctrine\PostGIS\Types\PostGISType;

#[ORM\Entity]
class MyEntity
{
/**
* @Column(type="geometry")
*/
private $geometry;

/**
* @Column(type="geography")
*/
private $geography;
#[ORM\Column(type: PostGISType::GEOMETRY)]
private string $geometry;

#[ORM\Column(type: PostGISType::GEOGRAPHY)]
private string $geography;
}
```

Expand All @@ -140,23 +139,39 @@ There are 2 options you can set to define the geometry.
### Example

```php
/** @Entity */
use Doctrine\ORM\Mapping as ORM;
use Jsor\Doctrine\PostGIS\Types\PostGISType;

#[ORM\Entity]
class MyEntity
{
/**
* @Column(type="geometry", options={"geometry_type"="POINT"})
*/
private $point;

/**
* @Column(type="geometry", options={"geometry_type"="POINTZM"})
*/
private $point4D;

/**
* @Column(type="geometry", options={"geometry_type"="POINT", "srid"=3785})
*/
private $pointWithSRID;
#[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;
}
}
```

Expand All @@ -169,31 +184,29 @@ to retain as much information as possible (like SRID's). Read more in the
### Example

```php
$entity = new MyEntity();

$entity->setPoint('POINT(37.4220761 -122.0845187)');
$entity->setPoint4D('POINT(1 2 3 4)');
$entity->setPointWithSRID('SRID=3785;POINT(37.4220761 -122.0845187)');
$entity = new MyEntity(
point: 'POINT(37.4220761 -122.0845187)',
point4D: 'POINT(1 2 3 4)',
pointWithSRID: 'SRID=3785;POINT(37.4220761 -122.0845187)',
);
```

Spatial Indexes
---------------

You can define [spatial indexes](https://postgis.net/docs/using_postgis_dbmanagement.html#gist_indexes)
for your geometry columns.
for your geometry fields.

Simply set the `spatial` flag for indexes.

```php
/**
* @Entity
* @Table(
* indexes={
* @Index(name="idx_point", columns={"point"}, flags={"spatial"}),
* @Index(name="idx_polygon", columns={"polygon"}, flags={"spatial"})
* }
* )
*/
use Doctrine\ORM\Mapping as ORM;

#[ORM\Entity]
#[ORM\Index(
fields: ['pointWithSRID'],
flags: ['spatial'],
)]
class MyEntity
{
}
Expand Down Expand Up @@ -222,7 +235,7 @@ $configuration = new Doctrine\ORM\Configuration();

$configuration->addCustomStringFunction(
'ST_Distance',
'Jsor\Doctrine\PostGIS\Functions\ST_Distance'
Jsor\Doctrine\PostGIS\Functions\ST_Distance::class
);

$dbParams = [/***/];
Expand Down
7 changes: 2 additions & 5 deletions tests/AbstractFunctionalTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,14 @@

namespace Jsor\Doctrine\PostGIS;

use Doctrine\Common\Annotations\AnnotationReader;
use Doctrine\DBAL\Configuration as DBALConfiguration;
use Doctrine\DBAL\Connection;
use Doctrine\DBAL\DriverManager;
use Doctrine\DBAL\Types\Type;
use Doctrine\ORM\Configuration as ORMConfiguration;
use Doctrine\ORM\EntityManager;
use Doctrine\ORM\EntityManagerInterface;
use Doctrine\ORM\Mapping\Driver\AnnotationDriver;
use Doctrine\ORM\Mapping\Driver\AttributeDriver;
use Doctrine\ORM\Tools\SchemaTool;
use Doctrine\Persistence\Mapping\Driver\MappingDriver;
use Jsor\Doctrine\PostGIS\Event\DBALSchemaEventSubscriber;
Expand Down Expand Up @@ -151,9 +150,7 @@ protected function _setupConfiguration(ORMConfiguration $config): ORMConfigurati

protected function _getMappingDriver(): MappingDriver
{
$reader = new AnnotationReader();

return new AnnotationDriver($reader);
return new AttributeDriver([__DIR__ . '/fixtures/Entity']);
}

protected function _execFile($fileName): int
Expand Down
24 changes: 12 additions & 12 deletions tests/Event/ORMSchemaEventSubscriberTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,12 @@ public function testEntity(): void
'text' => 'foo',
'geometry' => 'POINT(1 1)',
'point' => 'POINT(1 1)',
'point2D' => 'SRID=3785;POINT(1 1)',
'point3DZ' => 'SRID=3785;POINT(1 1 1)',
'point3DM' => 'SRID=3785;POINTM(1 1 1)',
'point4D' => 'SRID=3785;POINT(1 1 1 1)',
'point2DNullable' => null,
'point2DNoSrid' => 'POINT(1 1)',
'point2d' => 'SRID=3785;POINT(1 1)',
'point3dz' => 'SRID=3785;POINT(1 1 1)',
'point3dm' => 'SRID=3785;POINTM(1 1 1)',
'point4d' => 'SRID=3785;POINT(1 1 1 1)',
'point2dNullable' => null,
'point2dNoSrid' => 'POINT(1 1)',
'geography' => 'SRID=4326;POINT(1 1)',
'pointGeography2d' => 'SRID=4326;POINT(1 1)',
'pointGeography2dSrid' => 'POINT(1 1)',
Expand All @@ -48,12 +48,12 @@ public function testEntity(): void
$entity = $em->find(PointsEntity::class, 1);

$this->assertEquals('POINT(1 1)', $entity->getPoint());
$this->assertEquals('SRID=3785;POINT(1 1)', $entity->getPoint2D());
$this->assertEquals('SRID=3785;POINT(1 1 1)', $entity->getPoint3DZ());
$this->assertEquals('SRID=3785;POINTM(1 1 1)', $entity->getPoint3DM());
$this->assertEquals('SRID=3785;POINT(1 1 1 1)', $entity->getPoint4D());
$this->assertNull($entity->getPoint2DNullable());
$this->assertEquals('POINT(1 1)', $entity->getPoint2DNoSrid());
$this->assertEquals('SRID=3785;POINT(1 1)', $entity->getPoint2d());
$this->assertEquals('SRID=3785;POINT(1 1 1)', $entity->getPoint3dz());
$this->assertEquals('SRID=3785;POINTM(1 1 1)', $entity->getPoint3dm());
$this->assertEquals('SRID=3785;POINT(1 1 1 1)', $entity->getPoint4d());
$this->assertNull($entity->getPoint2dNullable());
$this->assertEquals('POINT(1 1)', $entity->getPoint2dNoSrid());
$this->assertEquals('SRID=4326;POINT(1 1)', $entity->getPointGeography2d());
$this->assertEquals('SRID=4326;POINT(1 1)', $entity->getPointGeography2dSrid());
}
Expand Down
12 changes: 6 additions & 6 deletions tests/Functions/GeographyTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,12 @@ protected function setUp(): void
'text' => 'foo',
'geometry' => 'POINT(1 1)',
'point' => 'POINT(1 1)',
'point2D' => 'SRID=3785;POINT(1 1)',
'point3DZ' => 'SRID=3785;POINT(1 1 1)',
'point3DM' => 'SRID=3785;POINTM(1 1 1)',
'point4D' => 'SRID=3785;POINT(1 1 1 1)',
'point2DNullable' => null,
'point2DNoSrid' => 'POINT(1 1)',
'point2d' => 'SRID=3785;POINT(1 1)',
'point3dz' => 'SRID=3785;POINT(1 1 1)',
'point3dm' => 'SRID=3785;POINTM(1 1 1)',
'point4d' => 'SRID=3785;POINT(1 1 1 1)',
'point2dNullable' => null,
'point2dNoSrid' => 'POINT(1 1)',
'geography' => 'SRID=4326;POINT(1 1)',
'pointGeography2d' => 'SRID=4326;POINT(1 1)',
'pointGeography2dSrid' => 'POINT(1 1)',
Expand Down
12 changes: 6 additions & 6 deletions tests/Functions/GeometryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,12 @@ protected function setUp(): void
'text' => 'foo',
'geometry' => 'POINT(1 1)',
'point' => 'POINT(1 1)',
'point2D' => 'SRID=3785;POINT(1 1)',
'point3DZ' => 'SRID=3785;POINT(1 1 1)',
'point3DM' => 'SRID=3785;POINTM(1 1 1)',
'point4D' => 'SRID=3785;POINT(1 1 1 1)',
'point2DNullable' => null,
'point2DNoSrid' => 'POINT(1 1)',
'point2d' => 'SRID=3785;POINT(1 1)',
'point3dz' => 'SRID=3785;POINT(1 1 1)',
'point3dm' => 'SRID=3785;POINTM(1 1 1)',
'point4d' => 'SRID=3785;POINT(1 1 1 1)',
'point2dNullable' => null,
'point2dNoSrid' => 'POINT(1 1)',
'geography' => 'SRID=4326;POINT(1 1)',
'pointGeography2d' => 'SRID=4326;POINT(1 1)',
'pointGeography2dSrid' => 'POINT(1 1)',
Expand Down
12 changes: 6 additions & 6 deletions tests/Functions/GeometryTypeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,12 @@ protected function setUp(): void
'text' => 'foo',
'geometry' => 'POINT(1 1)',
'point' => 'POINT(1 1)',
'point2D' => 'SRID=3785;POINT(1 1)',
'point3DZ' => 'SRID=3785;POINT(1 1 1)',
'point3DM' => 'SRID=3785;POINTM(1 1 1)',
'point4D' => 'SRID=3785;POINT(1 1 1 1)',
'point2DNullable' => null,
'point2DNoSrid' => 'POINT(1 1)',
'point2d' => 'SRID=3785;POINT(1 1)',
'point3dz' => 'SRID=3785;POINT(1 1 1)',
'point3dm' => 'SRID=3785;POINTM(1 1 1)',
'point4d' => 'SRID=3785;POINT(1 1 1 1)',
'point2dNullable' => null,
'point2dNoSrid' => 'POINT(1 1)',
'geography' => 'SRID=4326;POINT(1 1)',
'pointGeography2d' => 'SRID=4326;POINT(1 1)',
'pointGeography2dSrid' => 'POINT(1 1)',
Expand Down
12 changes: 6 additions & 6 deletions tests/Functions/ST_3DClosestPointTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,12 @@ protected function setUp(): void
'text' => 'foo',
'geometry' => 'POINT(1 1)',
'point' => 'POINT(1 1)',
'point2D' => 'SRID=3785;POINT(1 1)',
'point3DZ' => 'SRID=3785;POINT(1 1 1)',
'point3DM' => 'SRID=3785;POINTM(1 1 1)',
'point4D' => 'SRID=3785;POINT(1 1 1 1)',
'point2DNullable' => null,
'point2DNoSrid' => 'POINT(1 1)',
'point2d' => 'SRID=3785;POINT(1 1)',
'point3dz' => 'SRID=3785;POINT(1 1 1)',
'point3dm' => 'SRID=3785;POINTM(1 1 1)',
'point4d' => 'SRID=3785;POINT(1 1 1 1)',
'point2dNullable' => null,
'point2dNoSrid' => 'POINT(1 1)',
'geography' => 'SRID=4326;POINT(1 1)',
'pointGeography2d' => 'SRID=4326;POINT(1 1)',
'pointGeography2dSrid' => 'POINT(1 1)',
Expand Down
12 changes: 6 additions & 6 deletions tests/Functions/ST_3DDFullyWithinTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,12 @@ protected function setUp(): void
'text' => 'foo',
'geometry' => 'POINT(1 1)',
'point' => 'POINT(1 1)',
'point2D' => 'SRID=3785;POINT(1 1)',
'point3DZ' => 'SRID=3785;POINT(1 1 1)',
'point3DM' => 'SRID=3785;POINTM(1 1 1)',
'point4D' => 'SRID=3785;POINT(1 1 1 1)',
'point2DNullable' => null,
'point2DNoSrid' => 'POINT(1 1)',
'point2d' => 'SRID=3785;POINT(1 1)',
'point3dz' => 'SRID=3785;POINT(1 1 1)',
'point3dm' => 'SRID=3785;POINTM(1 1 1)',
'point4d' => 'SRID=3785;POINT(1 1 1 1)',
'point2dNullable' => null,
'point2dNoSrid' => 'POINT(1 1)',
'geography' => 'SRID=4326;POINT(1 1)',
'pointGeography2d' => 'SRID=4326;POINT(1 1)',
'pointGeography2dSrid' => 'POINT(1 1)',
Expand Down
12 changes: 6 additions & 6 deletions tests/Functions/ST_3DDWithinTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,12 @@ protected function setUp(): void
'text' => 'foo',
'geometry' => 'POINT(1 1)',
'point' => 'POINT(1 1)',
'point2D' => 'SRID=3785;POINT(1 1)',
'point3DZ' => 'SRID=3785;POINT(1 1 1)',
'point3DM' => 'SRID=3785;POINTM(1 1 1)',
'point4D' => 'SRID=3785;POINT(1 1 1 1)',
'point2DNullable' => null,
'point2DNoSrid' => 'POINT(1 1)',
'point2d' => 'SRID=3785;POINT(1 1)',
'point3dz' => 'SRID=3785;POINT(1 1 1)',
'point3dm' => 'SRID=3785;POINTM(1 1 1)',
'point4d' => 'SRID=3785;POINT(1 1 1 1)',
'point2dNullable' => null,
'point2dNoSrid' => 'POINT(1 1)',
'geography' => 'SRID=4326;POINT(1 1)',
'pointGeography2d' => 'SRID=4326;POINT(1 1)',
'pointGeography2dSrid' => 'POINT(1 1)',
Expand Down
12 changes: 6 additions & 6 deletions tests/Functions/ST_3DDistanceTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,12 @@ protected function setUp(): void
'text' => 'foo',
'geometry' => 'POINT(1 1)',
'point' => 'POINT(1 1)',
'point2D' => 'SRID=3785;POINT(1 1)',
'point3DZ' => 'SRID=3785;POINT(1 1 1)',
'point3DM' => 'SRID=3785;POINTM(1 1 1)',
'point4D' => 'SRID=3785;POINT(1 1 1 1)',
'point2DNullable' => null,
'point2DNoSrid' => 'POINT(1 1)',
'point2d' => 'SRID=3785;POINT(1 1)',
'point3dz' => 'SRID=3785;POINT(1 1 1)',
'point3dm' => 'SRID=3785;POINTM(1 1 1)',
'point4d' => 'SRID=3785;POINT(1 1 1 1)',
'point2dNullable' => null,
'point2dNoSrid' => 'POINT(1 1)',
'geography' => 'SRID=4326;POINT(1 1)',
'pointGeography2d' => 'SRID=4326;POINT(1 1)',
'pointGeography2dSrid' => 'POINT(1 1)',
Expand Down
12 changes: 6 additions & 6 deletions tests/Functions/ST_3DIntersectsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,12 @@ protected function setUp(): void
'text' => 'foo',
'geometry' => 'POINT(1 1)',
'point' => 'POINT(1 1)',
'point2D' => 'SRID=3785;POINT(1 1)',
'point3DZ' => 'SRID=3785;POINT(1 1 1)',
'point3DM' => 'SRID=3785;POINTM(1 1 1)',
'point4D' => 'SRID=3785;POINT(1 1 1 1)',
'point2DNullable' => null,
'point2DNoSrid' => 'POINT(1 1)',
'point2d' => 'SRID=3785;POINT(1 1)',
'point3dz' => 'SRID=3785;POINT(1 1 1)',
'point3dm' => 'SRID=3785;POINTM(1 1 1)',
'point4d' => 'SRID=3785;POINT(1 1 1 1)',
'point2dNullable' => null,
'point2dNoSrid' => 'POINT(1 1)',
'geography' => 'SRID=4326;POINT(1 1)',
'pointGeography2d' => 'SRID=4326;POINT(1 1)',
'pointGeography2dSrid' => 'POINT(1 1)',
Expand Down
12 changes: 6 additions & 6 deletions tests/Functions/ST_3DLengthTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,12 @@ protected function setUp(): void
'text' => 'foo',
'geometry' => 'POINT(1 1)',
'point' => 'POINT(1 1)',
'point2D' => 'SRID=3785;POINT(1 1)',
'point3DZ' => 'SRID=3785;POINT(1 1 1)',
'point3DM' => 'SRID=3785;POINTM(1 1 1)',
'point4D' => 'SRID=3785;POINT(1 1 1 1)',
'point2DNullable' => null,
'point2DNoSrid' => 'POINT(1 1)',
'point2d' => 'SRID=3785;POINT(1 1)',
'point3dz' => 'SRID=3785;POINT(1 1 1)',
'point3dm' => 'SRID=3785;POINTM(1 1 1)',
'point4d' => 'SRID=3785;POINT(1 1 1 1)',
'point2dNullable' => null,
'point2dNoSrid' => 'POINT(1 1)',
'geography' => 'SRID=4326;POINT(1 1)',
'pointGeography2d' => 'SRID=4326;POINT(1 1)',
'pointGeography2dSrid' => 'POINT(1 1)',
Expand Down
12 changes: 6 additions & 6 deletions tests/Functions/ST_3DLongestLineTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,12 @@ protected function setUp(): void
'text' => 'foo',
'geometry' => 'POINT(1 1)',
'point' => 'POINT(1 1)',
'point2D' => 'SRID=3785;POINT(1 1)',
'point3DZ' => 'SRID=3785;POINT(1 1 1)',
'point3DM' => 'SRID=3785;POINTM(1 1 1)',
'point4D' => 'SRID=3785;POINT(1 1 1 1)',
'point2DNullable' => null,
'point2DNoSrid' => 'POINT(1 1)',
'point2d' => 'SRID=3785;POINT(1 1)',
'point3dz' => 'SRID=3785;POINT(1 1 1)',
'point3dm' => 'SRID=3785;POINTM(1 1 1)',
'point4d' => 'SRID=3785;POINT(1 1 1 1)',
'point2dNullable' => null,
'point2dNoSrid' => 'POINT(1 1)',
'geography' => 'SRID=4326;POINT(1 1)',
'pointGeography2d' => 'SRID=4326;POINT(1 1)',
'pointGeography2dSrid' => 'POINT(1 1)',
Expand Down

0 comments on commit f4c81aa

Please sign in to comment.