diff --git a/CHANGELOG.md b/CHANGELOG.md index b9237c1..438d8a3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -16,6 +16,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Removed automatic SRID transformation - Removed st prefixed builder functions (e.g. `stSelect`, `stWhere`, ...) - Removed `GeometryType` Enum +- Renamed `toString` to `toSqlString` on `Box` classes ### Added @@ -26,6 +27,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Added `AsGeometry` and `AsGeography` database expressions - Added `fromString()` to `Box` classes to create a box from a string - Added `JsonSerializable` to `Box2D` and `Box3D` +- Added `Stringable` interface to all box classes ### Improved diff --git a/src/Cast/BBoxCast.php b/src/Cast/BBoxCast.php index b6390e5..14caa6a 100644 --- a/src/Cast/BBoxCast.php +++ b/src/Cast/BBoxCast.php @@ -56,6 +56,6 @@ public function get($model, string $key, mixed $value, array $attributes) */ public function set($model, string $key, mixed $value, array $attributes) { - return $value->toString(); + return $value->toSqlString(); } } diff --git a/src/Data/Boxes/Box.php b/src/Data/Boxes/Box.php index 8fc58ee..358f02d 100644 --- a/src/Data/Boxes/Box.php +++ b/src/Data/Boxes/Box.php @@ -6,12 +6,13 @@ use Illuminate\Contracts\Database\Eloquent\Castable; use Illuminate\Contracts\Database\Query\Expression as ExpressionContract; use JsonSerializable; +use Stringable; -abstract class Box implements Castable, ExpressionContract, JsonSerializable +abstract class Box implements Castable, ExpressionContract, Stringable, JsonSerializable { abstract public static function fromString(string $box): self; - abstract public function toString(): string; + abstract public function toSqlString(): string; /** * @return BBoxCast diff --git a/src/Data/Boxes/Box2D.php b/src/Data/Boxes/Box2D.php index b5f4146..99cfcec 100644 --- a/src/Data/Boxes/Box2D.php +++ b/src/Data/Boxes/Box2D.php @@ -36,7 +36,7 @@ public function getYMax(): float return $this->yMax; } - public function toString(): string + public function toSqlString(): string { $min = GeometryHelper::stringifyFloat($this->xMin).' '.GeometryHelper::stringifyFloat($this->yMin); $max = GeometryHelper::stringifyFloat($this->xMax).' '.GeometryHelper::stringifyFloat($this->yMax); @@ -44,9 +44,14 @@ public function toString(): string return "BOX({$min},{$max})"; } + public function __toString(): string + { + return $this->toSqlString(); + } + public function getValue(Grammar $grammar): string { - return $grammar->quoteString($this->toString()).'::box2d'; + return $grammar->quoteString($this->toSqlString()).'::box2d'; } public static function fromString(string $box): self diff --git a/src/Data/Boxes/Box3D.php b/src/Data/Boxes/Box3D.php index 2f1a05a..71fb4f3 100644 --- a/src/Data/Boxes/Box3D.php +++ b/src/Data/Boxes/Box3D.php @@ -46,7 +46,7 @@ public function getZMax(): float return $this->zMax; } - public function toString(): string + public function toSqlString(): string { $min = GeometryHelper::stringifyFloat($this->xMin).' '.GeometryHelper::stringifyFloat($this->yMin).' '.GeometryHelper::stringifyFloat($this->zMin); $max = GeometryHelper::stringifyFloat($this->xMax).' '.GeometryHelper::stringifyFloat($this->yMax).' '.GeometryHelper::stringifyFloat($this->zMax); @@ -54,9 +54,14 @@ public function toString(): string return "BOX3D({$min},{$max})"; } + public function __toString(): string + { + return $this->toSqlString(); + } + public function getValue(Grammar $grammar): string { - return $grammar->quoteString($this->toString()).'::box3d'; + return $grammar->quoteString($this->toSqlString()).'::box3d'; } public static function fromString(string $box): self