-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
18 changed files
with
506 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
<?php | ||
|
||
namespace GlaivePro\SF\MariaDB; | ||
|
||
use GlaivePro\SF\OGC\Contracts\Curve as OGCCurve; | ||
|
||
/** | ||
* Curve model with MariaDB-specific functions. | ||
*/ | ||
class Curve extends Geometry implements OGCCurve | ||
{ | ||
use \GlaivePro\SF\OGC\Traits\Curve; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
<?php | ||
|
||
namespace GlaivePro\SF\MariaDB; | ||
|
||
use GlaivePro\SF\Exceptions\MethodNotImplemented; | ||
use GlaivePro\SF\Expression; | ||
use GlaivePro\SF\OGC\Contracts\Geometry as GeometryInterface; | ||
use GlaivePro\SF\OGC\Geometry as OGCGeometry; | ||
|
||
/** | ||
* Geometry model with MariaDB-specific functions. | ||
*/ | ||
class Geometry extends OGCGeometry | ||
{ | ||
protected const sfc = Sfc::class; | ||
|
||
/** | ||
* There is no native SetSRID in MariaDB, but it's important enough to support it. | ||
*/ | ||
public function setSRID(int $srid): static | ||
{ | ||
return static::fromMethod( | ||
'ST_GeomFromWKB', | ||
static::fromMethod('ST_AsBinary', $this), | ||
$srid, | ||
); | ||
} | ||
|
||
public function coordinateDimension(): Expression // Integer-valued expression | ||
{ | ||
throw new MethodNotImplemented; | ||
} | ||
|
||
public function is3D(): Expression // Boolean-valued expression | ||
{ | ||
throw new MethodNotImplemented; | ||
} | ||
|
||
public function isMeasured(): Expression // Boolean-valued expression | ||
{ | ||
throw new MethodNotImplemented; | ||
} | ||
|
||
public function locateAlong(float $mValue): GeometryInterface | ||
{ | ||
throw new MethodNotImplemented; | ||
} | ||
|
||
public function locateBetween(float $mStart, float $mEnd): GeometryInterface | ||
{ | ||
throw new MethodNotImplemented; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
<?php | ||
|
||
namespace GlaivePro\SF\MariaDB; | ||
|
||
use GlaivePro\SF\OGC\Contracts\GeometryCollection as OGCGeometryCollection; | ||
|
||
/** | ||
* GeometryCollection model with MariaDB-specific functions. | ||
*/ | ||
class GeometryCollection extends Geometry implements OGCGeometryCollection | ||
{ | ||
use \GlaivePro\SF\OGC\Traits\GeometryCollection; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
<?php | ||
|
||
namespace GlaivePro\SF\MariaDB; | ||
|
||
use GlaivePro\SF\OGC\Contracts\LineString as OGCLineString; | ||
|
||
/** | ||
* LineString model with MariaDB-specific functions. | ||
*/ | ||
class LineString extends Curve implements OGCLineString | ||
{ | ||
use \GlaivePro\SF\OGC\Traits\LineString; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
<?php | ||
|
||
namespace GlaivePro\SF\MariaDB; | ||
|
||
use GlaivePro\SF\OGC\Contracts\MultiCurve as OGCMultiCurve; | ||
|
||
/** | ||
* MultiCurve model with MariaDB-specific functions. | ||
*/ | ||
class MultiCurve extends GeometryCollection implements OGCMultiCurve | ||
{ | ||
use \GlaivePro\SF\OGC\Traits\CurveBasic; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
<?php | ||
|
||
namespace GlaivePro\SF\MariaDB; | ||
|
||
use GlaivePro\SF\OGC\Contracts\MultiLineString as OGCMultiLineString; | ||
|
||
/** | ||
* MultiLineString model with MariaDB-specific functions. | ||
*/ | ||
class MultiLineString extends MultiCurve implements OGCMultiLineString {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
<?php | ||
|
||
namespace GlaivePro\SF\MariaDB; | ||
|
||
use GlaivePro\SF\OGC\Contracts\MultiPoint as OGCMultiPoint; | ||
|
||
/** | ||
* MultiPoint model with MariaDB-specific functions. | ||
*/ | ||
class MultiPoint extends GeometryCollection implements OGCMultiPoint {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
<?php | ||
|
||
namespace GlaivePro\SF\MariaDB; | ||
|
||
use GlaivePro\SF\OGC\Contracts\MultiPolygon as OGCMultiPolygon; | ||
|
||
/** | ||
* MultiPolygon model with MariaDB-specific functions. | ||
*/ | ||
class MultiPolygon extends MultiSurface implements OGCMultiPolygon {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
<?php | ||
|
||
namespace GlaivePro\SF\MariaDB; | ||
|
||
use GlaivePro\SF\OGC\Contracts\MultiSurface as OGCMultiSurface; | ||
|
||
/** | ||
* MultiSurface model with MariaDB-specific functions. | ||
*/ | ||
class MultiSurface extends GeometryCollection implements OGCMultiSurface | ||
{ | ||
use \GlaivePro\SF\OGC\Traits\SurfaceBasic; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
<?php | ||
|
||
namespace GlaivePro\SF\MariaDB; | ||
|
||
use GlaivePro\SF\Exceptions\MethodNotImplemented; | ||
use GlaivePro\SF\Expression; | ||
use GlaivePro\SF\OGC\Contracts\Point as OGCPoint; | ||
|
||
/** | ||
* Point model with MariaDB-specific functions. | ||
*/ | ||
class Point extends Geometry implements OGCPoint | ||
{ | ||
use \GlaivePro\SF\OGC\Traits\Point; | ||
|
||
public function Z(): Expression | ||
{ | ||
throw new MethodNotImplemented; | ||
} | ||
|
||
public function M(): Expression | ||
{ | ||
throw new MethodNotImplemented(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
<?php | ||
|
||
namespace GlaivePro\SF\MariaDB; | ||
|
||
use GlaivePro\SF\Expression; | ||
use GlaivePro\SF\OGC\Contracts\Polygon as OGCPolygon; | ||
|
||
/** | ||
* Polygon model with MariaDB-specific functions. | ||
*/ | ||
class Polygon extends Surface implements OGCPolygon | ||
{ | ||
use \GlaivePro\SF\OGC\Traits\Polygon; | ||
|
||
public function numInteriorRing(): Expression // Integer-valued expression | ||
{ | ||
return $this->wrap('ST_NumInteriorRings'); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
<?php | ||
|
||
namespace GlaivePro\SF\MariaDB; | ||
|
||
use GlaivePro\SF\Exceptions\MethodNotImplemented; | ||
use GlaivePro\SF\OGC\Sfc as OGCSfc; | ||
|
||
/** | ||
* Implements constructors available in MariaDB. | ||
*/ | ||
class Sfc extends OGCSfc | ||
{ | ||
/** | ||
* Calls `fromMethod` on the desired class. | ||
* | ||
* We have to specify PostGIS-specific classes here. | ||
*/ | ||
protected static function callFromMethod(string $method, array $args): Geometry | ||
{ | ||
$class = match ($method) { | ||
'geometry' => Geometry::class, | ||
'geometryCollection' => GeometryCollection::class, | ||
'lineString' => LineString::class, | ||
'multiCurve' => MultiCurve::class, | ||
'multiLineString' => MultiLineString::class, | ||
'multiPoint' => MultiPoint::class, | ||
'multiPolygon' => MultiPolygon::class, | ||
'point' => Point::class, | ||
'polygon' => Polygon::class, | ||
}; | ||
|
||
return $class::fromMethod(...$args); | ||
} | ||
|
||
/** | ||
* Create a Point. | ||
* | ||
* Unlike POINT in MariaDB, this also accepts POINT(x, y, srid) | ||
* and will set the SRID on the created POINT in such case. | ||
*/ | ||
public static function point(float $x, float $y, int $srid = null): Point | ||
{ | ||
$point = Point::fromMethod('Point', $x, $y); | ||
|
||
if (\is_null($srid)) | ||
return $point; | ||
|
||
return $point->setSRID($srid); | ||
} | ||
|
||
/** | ||
* Not implemented in MariaDB. | ||
*/ | ||
public static function bdPolyFromWKB(string $WKBMultiLineString, int $SRID = null): Polygon | ||
{ | ||
throw new MethodNotImplemented; | ||
} | ||
|
||
/** | ||
* Not implemented in MariaDB. | ||
*/ | ||
public static function bdPolyFromText(string $multiLineStringTaggedText, int $SRID = null): Polygon | ||
{ | ||
throw new MethodNotImplemented; | ||
} | ||
|
||
/** | ||
* Not implemented in MariaDB. | ||
*/ | ||
public static function bdMPolyFromWKB(string $WKBMultiLineString, int $SRID = null): MultiPolygon | ||
{ | ||
throw new MethodNotImplemented; | ||
} | ||
|
||
/** | ||
* Not implemented in MariaDB. | ||
*/ | ||
public static function bdMPolyFromText(string $multiLineStringTaggedText, int $SRID = null): MultiPolygon | ||
{ | ||
throw new MethodNotImplemented; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
<?php | ||
|
||
namespace GlaivePro\SF\MariaDB; | ||
|
||
use GlaivePro\SF\OGC\Contracts\Surface as OGCSurface; | ||
|
||
/** | ||
* Surface model with MariaDB-specific functions. | ||
*/ | ||
class Surface extends Geometry implements OGCSurface | ||
{ | ||
use \GlaivePro\SF\OGC\Traits\Surface; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
<?php | ||
|
||
namespace GlaivePro\SF\Tests\MariaDB; | ||
|
||
use PHPUnit\Framework\TestCase; | ||
use GlaivePro\SF\MariaDB\Sfc; | ||
|
||
class ConstructorTest extends TestCase | ||
{ | ||
public function testPointConstructors(): void | ||
{ | ||
$point = Sfc::point(1, 3); | ||
$this->assertSame( | ||
'Point(?, ?)', | ||
(string) $point, | ||
); | ||
$this->assertEquals([1, 3], $point->bindings); | ||
|
||
$pointWithSrid = Sfc::point(1, 3, 4326); | ||
$this->assertSame( | ||
'ST_GeomFromWKB(ST_AsBinary(Point(?, ?)), ?)', | ||
(string) $pointWithSrid, | ||
); | ||
$this->assertEquals([1, 3, 4326], $pointWithSrid->bindings); | ||
} | ||
} |
Oops, something went wrong.