Skip to content

Commit

Permalink
Remove GeometryEngineRegistry
Browse files Browse the repository at this point in the history
  • Loading branch information
BenMorel committed Jun 24, 2022
1 parent 6632e35 commit 1140be4
Show file tree
Hide file tree
Showing 22 changed files with 425 additions and 273 deletions.
83 changes: 83 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,88 @@
# Changelog

## Unreleased

💥 **Breaking changes**

The global `GeometryEngineRegistry` is gone. All convenience methods that rely on the `GeometryEngine` are deprecated, and need the `GeometryEngine` to be passed explicitly as an extra argument.
You should now explicitly call the `GeometryEngine`, that you can get injected with your dependency injection container.

For example, the following call:

```php
$lineString->length();
```

Should be replaced with:

```php
$geometryEngine->length($lineString);
```

You can still call it this way for now:

```php
$lineString->length($geometryEngine);
```

But this behaviour is deprecated and will be removed in a future version.

**Detail of breaking changes**

The following class has been removed:

- `GeometryEngineRegistry`

The following method has been added:

- `GeometryEngine::isRing()`

The following method signatures have been changed:

- `GeometryEngine::boundingPolygons()`

The following methods have been deprecated, and now need an extra `GeometryEngine` parameter:

- `Curve::isClosed()`
- `Curve::isRing()`
- `Curve::length()`
- `Geometry::boundary()`
- `Geometry::buffer()`
- `Geometry::centroid()`
- `Geometry::contains()`
- `Geometry::convexHull()`
- `Geometry::crosses()`
- `Geometry::difference()`
- `Geometry::disjoint()`
- `Geometry::distance()`
- `Geometry::equals()`
- `Geometry::envelope()`
- `Geometry::intersection()`
- `Geometry::intersects()`
- `Geometry::isSimple()`
- `Geometry::isValid()`
- `Geometry::locateAlong()`
- `Geometry::locateBetween()`
- `Geometry::maxDistance()`
- `Geometry::overlaps()`
- `Geometry::relate()`
- `Geometry::simplify()`
- `Geometry::snapToGrid()`
- `Geometry::symDifference()`
- `Geometry::touches()`
- `Geometry::transform()`
- `Geometry::union()`
- `Geometry::within()`
- `MultiCurve::isClosed()`
- `MultiCurve::length()`
- `MultiSurface::area()`
- `MultiSurface::pointOnSurface()`
- `Point::azimuth()`
- `PolyhedralSurface::boundingPolygons()`
- `PolyhedralSurface::isClosed()`
- `Surface::area()`
- `Surface::pointOnSurface()`

## [0.7.1](https://github.com/brick/geo/releases/tag/0.7.1) - 2021-11-06

🐛 **Fixes**
Expand Down
16 changes: 6 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -77,11 +77,10 @@ Following is a step-by-step guide for all possible configurations:
- Use this bootstrap code in your project:

```php
use Brick\Geo\Engine\GeometryEngineRegistry;
use Brick\Geo\Engine\PDOEngine;

$pdo = new PDO('mysql:host=localhost', 'root', '');
GeometryEngineRegistry::set(new PDOEngine($pdo));
$geometryEngine = new PDOEngine($pdo);
```

Update the code with your own connection parameters, or use an existing `PDO` connection if you have one (recommended).
Expand Down Expand Up @@ -109,11 +108,10 @@ Just ensure that your MariaDB version is `5.5` or greater.
- Use this bootstrap code in your project:

```php
use Brick\Geo\Engine\GeometryEngineRegistry;
use Brick\Geo\Engine\PDOEngine;

$pdo = new PDO('pgsql:host=localhost', 'postgres', '');
GeometryEngineRegistry::set(new PDOEngine($pdo));
$geometryEngine = new PDOEngine($pdo);
```

Update the code with your own connection parameters, or use an existing `PDO` connection if you have one (recommended).
Expand Down Expand Up @@ -149,12 +147,11 @@ all you need to do is create an additional in-memory SQLite3 database just to po
- Use this bootstrap code in your project:

```php
use Brick\Geo\Engine\GeometryEngineRegistry;
use Brick\Geo\Engine\SQLite3Engine;

$sqlite3 = new SQLite3(':memory:');
$sqlite3->loadExtension('mod_spatialite.so');
GeometryEngineRegistry::set(new SQLite3Engine($sqlite3));
$geometryEngine = new SQLite3Engine($sqlite3);
```

- Depending on the functions you use, you will probably need to initialize the spatial metadata by running this query:
Expand All @@ -181,10 +178,9 @@ In this example we have created an in-memory database for our GIS calculations,
- Use this bootstrap code in your project:

```php
use Brick\Geo\Engine\GeometryEngineRegistry;
use Brick\Geo\Engine\GEOSEngine;

GeometryEngineRegistry::set(new GEOSEngine());
$geometryEngine = new GEOSEngine();
```
</details>

Expand Down Expand Up @@ -238,9 +234,9 @@ Example
use Brick\Geo\Polygon;

$polygon = Polygon::fromText('POLYGON ((0 0, 0 3, 3 3, 0 0))');
echo $polygon->area(); // 4.5
echo $geometryEngine->area($polygon); // 4.5

$centroid = $polygon->centroid();
$centroid = $geometryEngine->centroid($polygon);
echo $centroid->asText(); // POINT (1 2)
```

Expand Down
3 changes: 1 addition & 2 deletions phpunit-bootstrap.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
<?php

use Brick\Geo\Engine\GeometryEngineRegistry;
use Brick\Geo\Engine\PDOEngine;
use Brick\Geo\Engine\SQLite3Engine;
use Brick\Geo\Engine\GEOSEngine;
Expand Down Expand Up @@ -95,6 +94,6 @@
exit(1);
}

GeometryEngineRegistry::set($engine);
$GLOBALS['GEOMETRY_ENGINE'] = $engine;
}
})();
20 changes: 13 additions & 7 deletions src/Curve.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

namespace Brick\Geo;

use Brick\Geo\Engine\GeometryEngineRegistry;
use Brick\Geo\Engine\GeometryEngine;
use Brick\Geo\Exception\EmptyGeometryException;
use Brick\Geo\Exception\GeometryEngineException;

Expand All @@ -28,13 +28,15 @@ public function dimension() : int
/**
* Returns the length of this Curve in its associated spatial reference.
*
* @deprecated Please use `$geometryEngine->length()`.
*
* @noproxy
*
* @throws GeometryEngineException If the operation is not supported by the geometry engine.
*/
public function length() : float
public function length(GeometryEngine $geometryEngine) : float
{
return GeometryEngineRegistry::get()->length($this);
return $geometryEngine->length($this);
}

/**
Expand All @@ -56,13 +58,15 @@ abstract public function endPoint() : Point;
*
* The curve is closed if `startPoint()` == `endPoint()`.
*
* @deprecated Please use `$geometryEngine->isClosed()`.
*
* @noproxy
*
* @throws GeometryEngineException If the operation is not supported by the geometry engine.
*/
public function isClosed() : bool
public function isClosed(GeometryEngine $geometryEngine) : bool
{
return GeometryEngineRegistry::get()->isClosed($this);
return $geometryEngine->isClosed($this);
}

/**
Expand All @@ -73,12 +77,14 @@ public function isClosed() : bool
* The curve is closed if its start point is equal to its end point.
* The curve is simple if it does not pass through the same point more than once.
*
* @deprecated Please use `$geometryEngine->isRing()`.
*
* @noproxy
*
* @throws GeometryEngineException If the operation is not supported by the geometry engine.
*/
public function isRing() : bool
public function isRing(GeometryEngine $geometryEngine) : bool
{
return $this->isClosed() && $this->isSimple();
return $geometryEngine->isRing($this);
}
}
4 changes: 3 additions & 1 deletion src/Engine/DatabaseEngine.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@
use Brick\Geo\Curve;
use Brick\Geo\Exception\GeometryEngineException;
use Brick\Geo\Geometry;
use Brick\Geo\MultiPolygon;
use Brick\Geo\Point;
use Brick\Geo\Polygon;
use Brick\Geo\Proxy;

/**
Expand Down Expand Up @@ -422,7 +424,7 @@ public function maxDistance(Geometry $a, Geometry $b) : float
return $this->queryFloat('ST_MaxDistance', $a, $b);
}

public function boundingPolygons(Geometry $g) : Geometry
public function boundingPolygons(Polygon $p) : MultiPolygon
{
throw GeometryEngineException::unimplementedMethod(__METHOD__);
}
Expand Down
4 changes: 3 additions & 1 deletion src/Engine/GEOSEngine.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@
use Brick\Geo\IO\EWKBReader;
use Brick\Geo\IO\EWKBWriter;
use Brick\Geo\Geometry;
use Brick\Geo\MultiPolygon;
use Brick\Geo\Point;
use Brick\Geo\Polygon;
use GEOSWKBReader;
use GEOSWKBWriter;
use GEOSWKTReader;
Expand Down Expand Up @@ -358,7 +360,7 @@ public function maxDistance(Geometry $a, Geometry $b) : float
throw GeometryEngineException::unimplementedMethod(__METHOD__);
}

public function boundingPolygons(Geometry $g) : Geometry
public function boundingPolygons(Polygon $p) : MultiPolygon
{
throw GeometryEngineException::unimplementedMethod(__METHOD__);
}
Expand Down

0 comments on commit 1140be4

Please sign in to comment.