Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions src/Database/Type/GeometryType.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,13 @@ class GeometryType implements TypeInterface
*/
protected string $name = 'geometry';

/**
* Decorator method.
*
* @var (callable(\Brick\Geo\Geometry): \Brick\Geo\Geometry)|null
*/
protected $decorator = null;

/**
* GeometryType constructor.
*
Expand Down Expand Up @@ -70,6 +77,9 @@ public function toDatabase($value, DriverInterface $driver): ?string
}

$geometry = Geometry::parse($value)->getGeometry();
if ($this->decorator !== null) {
$geometry = call_user_func($this->decorator, $geometry);
}
$wkb = $geometry->asBinary();
if ($driver instanceof Driver\Mysql) {
$wkb = pack('V', $geometry->SRID()) . $wkb;
Expand Down Expand Up @@ -121,4 +131,18 @@ public function newId(): ?string
{
return null;
}

/**
* Add a decorator to the type converter.
* Useful to set the SRID of the geometry.
*
* @param (callable(\Brick\Geo\Geometry): \Brick\Geo\Geometry) $decorator The decorator method.
* @return static
*/
public function withDecorator(callable $decorator): static
{
$this->decorator = $decorator;

return $this;
}
}
Loading