From 7dff1f3d9fbd0061193f6b67cca618af1fc0fac4 Mon Sep 17 00:00:00 2001 From: Joseph Estefane Date: Tue, 3 Apr 2018 11:44:37 -0400 Subject: [PATCH 01/83] Use the schema defined in the Laravel configuration (database.connections.pgsql.schema) --- src/Eloquent/Builder.php | 5 ++++- src/Eloquent/PostgisTrait.php | 15 ++++++++++++--- 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/src/Eloquent/Builder.php b/src/Eloquent/Builder.php index d58c7f9..9818fea 100644 --- a/src/Eloquent/Builder.php +++ b/src/Eloquent/Builder.php @@ -24,6 +24,9 @@ protected function getPostgisFields() protected function asWKT(GeometryInterface $geometry) { - return $this->getQuery()->raw(sprintf("public.ST_GeogFromText('%s')", $geometry->toWKT())); + return $this->getQuery()->raw( + sprintf("%s.ST_GeogFromText('%s')", config('database.connections.pgsql.schema'), $geometry->toWKT()) + ); + } } diff --git a/src/Eloquent/PostgisTrait.php b/src/Eloquent/PostgisTrait.php index 6a7fc0b..c638c7f 100644 --- a/src/Eloquent/PostgisTrait.php +++ b/src/Eloquent/PostgisTrait.php @@ -33,15 +33,24 @@ protected function performInsert(EloquentBuilder $query, array $options = []) $attrs = $this->getPostgisType($key); switch (strtoupper($attrs['geomtype'])) { case 'GEOMETRY': - $this->attributes[$key] = $this->getConnection()->raw(sprintf("public.ST_GeomFromText('%s', '%d')", $value->toWKT(), $attrs['srid'])); + $this->attributes[$key] = $this->getConnection()->raw( + sprintf("%s.ST_GeomFromText('%s', '%d')", + config('database.connections.pgsql.schema'), $value->toWKT(), $attrs['srid']) + ); break; case 'GEOGRAPHY': default: - $this->attributes[$key] = $this->getConnection()->raw(sprintf("public.ST_GeogFromText('%s')", $value->toWKT())); + $this->attributes[$key] = $this->getConnection()->raw( + sprintf("%s.ST_GeogFromText('%s')", + config('database.connections.pgsql.schema'), $value->toWKT()) + ); break; } } else { - $this->attributes[$key] = $this->getConnection()->raw(sprintf("public.ST_GeomFromText('%s', 4326)", $value->toWKT())); + $this->attributes[$key] = $this->getConnection()->raw( + sprintf("%s.ST_GeomFromText('%s', 4326)", + config('database.connections.pgsql.schema'), $value->toWKT()) + ); } } } From e2c786d4073b15ca6d80eea0266da7e09b868566 Mon Sep 17 00:00:00 2001 From: Joseph Estefane Date: Tue, 3 Apr 2018 17:46:03 -0400 Subject: [PATCH 02/83] Added config and code to publish it. Adjusted reference to the config. --- config/postgis.php | 7 +++++++ src/DatabaseServiceProvider.php | 7 +++++++ src/Eloquent/Builder.php | 2 +- src/Eloquent/PostgisTrait.php | 6 +++--- 4 files changed, 18 insertions(+), 4 deletions(-) create mode 100644 config/postgis.php diff --git a/config/postgis.php b/config/postgis.php new file mode 100644 index 0000000..37ac3f5 --- /dev/null +++ b/config/postgis.php @@ -0,0 +1,7 @@ + 'public' // Schema for the Postgis extension + +]; \ No newline at end of file diff --git a/src/DatabaseServiceProvider.php b/src/DatabaseServiceProvider.php index 5e7e2af..ce30d3f 100644 --- a/src/DatabaseServiceProvider.php +++ b/src/DatabaseServiceProvider.php @@ -10,6 +10,13 @@ */ class DatabaseServiceProvider extends PostgresDatabaseServiceProvider { + public function boot() { + // Load the config + $config_path = __DIR__ . '/../config/postgis.php'; + $this->publishes([$config_path => config_path('postgis.php')], 'postgis'); + $this->mergeConfigFrom($config_path, 'postgis'); + } + /** * Register the service provider. * diff --git a/src/Eloquent/Builder.php b/src/Eloquent/Builder.php index 9818fea..5800fb2 100644 --- a/src/Eloquent/Builder.php +++ b/src/Eloquent/Builder.php @@ -25,7 +25,7 @@ protected function getPostgisFields() protected function asWKT(GeometryInterface $geometry) { return $this->getQuery()->raw( - sprintf("%s.ST_GeogFromText('%s')", config('database.connections.pgsql.schema'), $geometry->toWKT()) + sprintf("%s.ST_GeogFromText('%s')", config('postgis.schema'), $geometry->toWKT()) ); } diff --git a/src/Eloquent/PostgisTrait.php b/src/Eloquent/PostgisTrait.php index c638c7f..389e64e 100644 --- a/src/Eloquent/PostgisTrait.php +++ b/src/Eloquent/PostgisTrait.php @@ -35,21 +35,21 @@ protected function performInsert(EloquentBuilder $query, array $options = []) case 'GEOMETRY': $this->attributes[$key] = $this->getConnection()->raw( sprintf("%s.ST_GeomFromText('%s', '%d')", - config('database.connections.pgsql.schema'), $value->toWKT(), $attrs['srid']) + config('postgis.schema'), $value->toWKT(), $attrs['srid']) ); break; case 'GEOGRAPHY': default: $this->attributes[$key] = $this->getConnection()->raw( sprintf("%s.ST_GeogFromText('%s')", - config('database.connections.pgsql.schema'), $value->toWKT()) + config('postgis.schema'), $value->toWKT()) ); break; } } else { $this->attributes[$key] = $this->getConnection()->raw( sprintf("%s.ST_GeomFromText('%s', 4326)", - config('database.connections.pgsql.schema'), $value->toWKT()) + config('postgis.schema'), $value->toWKT()) ); } } From ead7ad1c3b51de239f717b96dd919bb45ff519bd Mon Sep 17 00:00:00 2001 From: Nick Barrett Date: Fri, 8 Jun 2018 10:11:23 +0800 Subject: [PATCH 03/83] tag specific version of bosnadev/database in composer.json --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index b4cfd8d..dda8fb4 100644 --- a/composer.json +++ b/composer.json @@ -6,7 +6,7 @@ "illuminate/database": "^5.2", "geo-io/wkb-parser": "^1.0", "jmikola/geojson": "^1.0", - "bosnadev/database": "~0.16" + "bosnadev/database": "0.18.1" }, "require-dev": { "phpunit/phpunit": "~4.5", From bab919c80809c043e7e37374e768869d5cb8279e Mon Sep 17 00:00:00 2001 From: Nick Barrett Date: Fri, 8 Jun 2018 10:16:57 +0800 Subject: [PATCH 04/83] fix failing tests as config function does not exist --- src/Eloquent/Builder.php | 2 +- src/Eloquent/PostgisTrait.php | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/Eloquent/Builder.php b/src/Eloquent/Builder.php index 5800fb2..c4f2989 100644 --- a/src/Eloquent/Builder.php +++ b/src/Eloquent/Builder.php @@ -25,7 +25,7 @@ protected function getPostgisFields() protected function asWKT(GeometryInterface $geometry) { return $this->getQuery()->raw( - sprintf("%s.ST_GeogFromText('%s')", config('postgis.schema'), $geometry->toWKT()) + sprintf("%s.ST_GeogFromText('%s')", function_exists('config') ? config('postgis.schema') : 'public', $geometry->toWKT()) ); } diff --git a/src/Eloquent/PostgisTrait.php b/src/Eloquent/PostgisTrait.php index 389e64e..50c79d2 100644 --- a/src/Eloquent/PostgisTrait.php +++ b/src/Eloquent/PostgisTrait.php @@ -35,21 +35,21 @@ protected function performInsert(EloquentBuilder $query, array $options = []) case 'GEOMETRY': $this->attributes[$key] = $this->getConnection()->raw( sprintf("%s.ST_GeomFromText('%s', '%d')", - config('postgis.schema'), $value->toWKT(), $attrs['srid']) + function_exists('config') ? config('postgis.schema') : 'public', $value->toWKT(), $attrs['srid']) ); break; case 'GEOGRAPHY': default: $this->attributes[$key] = $this->getConnection()->raw( sprintf("%s.ST_GeogFromText('%s')", - config('postgis.schema'), $value->toWKT()) + function_exists('config') ? config('postgis.schema') : 'public', $value->toWKT()) ); break; } } else { $this->attributes[$key] = $this->getConnection()->raw( sprintf("%s.ST_GeomFromText('%s', 4326)", - config('postgis.schema'), $value->toWKT()) + function_exists('config') ? config('postgis.schema') : 'public', $value->toWKT()) ); } } From a1c5e4738f97a822ad752a1af27dbf0259ef5cbc Mon Sep 17 00:00:00 2001 From: luizguilhermefr Date: Tue, 3 Jul 2018 20:16:50 -0300 Subject: [PATCH 05/83] add support to geometry update and separate some functions --- src/Eloquent/Builder.php | 14 ++++++----- src/Eloquent/PostgisTrait.php | 46 ++++++++++++++++++++--------------- 2 files changed, 35 insertions(+), 25 deletions(-) diff --git a/src/Eloquent/Builder.php b/src/Eloquent/Builder.php index c4f2989..6e6b234 100644 --- a/src/Eloquent/Builder.php +++ b/src/Eloquent/Builder.php @@ -9,7 +9,8 @@ public function update(array $values) { foreach ($values as $key => &$value) { if ($value instanceof GeometryInterface) { - $value = $this->asWKT($value); + $attrs = $this->getPostgisType($key); + $value = $this->asWKT($value, $attrs); } } @@ -21,12 +22,13 @@ protected function getPostgisFields() return $this->getModel()->getPostgisFields(); } - - protected function asWKT(GeometryInterface $geometry) + protected function getPostgisType($key) { - return $this->getQuery()->raw( - sprintf("%s.ST_GeogFromText('%s')", function_exists('config') ? config('postgis.schema') : 'public', $geometry->toWKT()) - ); + return $this->getModel()->getPostgisType($key); + } + protected function asWKT(GeometryInterface $geometry, $attrs) + { + return $this->getModel()->asWKT($geometry, $attrs); } } diff --git a/src/Eloquent/PostgisTrait.php b/src/Eloquent/PostgisTrait.php index 50c79d2..59791f6 100644 --- a/src/Eloquent/PostgisTrait.php +++ b/src/Eloquent/PostgisTrait.php @@ -24,6 +24,31 @@ public function newEloquentBuilder($query) return new Builder($query); } + protected function geogFromText(GeometryInterface $geometry) + { + return $this->getConnection()->raw(sprintf("%s.ST_GeogFromText('%s')", + function_exists('config') ? config('postgis.schema') : 'public', $geometry->toWKT())); + } + + protected function geomFromText(GeometryInterface $geometry, $srid = 4326) + { + return $this->getConnection()->raw(sprintf("%s.ST_GeomFromText('%s', '%d')", + function_exists('config') ? config('postgis.schema') : 'public', $geometry->toWKT(), $srid)); + } + + protected function asWKT(GeometryInterface $geometry, $attrs) + { + switch (strtoupper($attrs['geomtype'])) { + case 'GEOMETRY': + return $this->geomFromText($geometry, $attrs['srid']); + break; + case 'GEOGRAPHY': + default: + return $this->geogFromText($geometry); + break; + } + } + protected function performInsert(EloquentBuilder $query, array $options = []) { foreach ($this->attributes as $key => $value) { @@ -31,26 +56,9 @@ protected function performInsert(EloquentBuilder $query, array $options = []) $this->geometries[$key] = $value; //Preserve the geometry objects prior to the insert if (! $value instanceof GeometryCollection) { $attrs = $this->getPostgisType($key); - switch (strtoupper($attrs['geomtype'])) { - case 'GEOMETRY': - $this->attributes[$key] = $this->getConnection()->raw( - sprintf("%s.ST_GeomFromText('%s', '%d')", - function_exists('config') ? config('postgis.schema') : 'public', $value->toWKT(), $attrs['srid']) - ); - break; - case 'GEOGRAPHY': - default: - $this->attributes[$key] = $this->getConnection()->raw( - sprintf("%s.ST_GeogFromText('%s')", - function_exists('config') ? config('postgis.schema') : 'public', $value->toWKT()) - ); - break; - } + $this->attributes[$key] = $this->asWKT($value, $attrs); } else { - $this->attributes[$key] = $this->getConnection()->raw( - sprintf("%s.ST_GeomFromText('%s', 4326)", - function_exists('config') ? config('postgis.schema') : 'public', $value->toWKT()) - ); + $this->attributes[$key] = $this->geomFromText($value); } } } From 6261e1c0d72ea5430b23bafa451fbf53ce88782a Mon Sep 17 00:00:00 2001 From: luizguilhermefr Date: Tue, 3 Jul 2018 21:22:25 -0300 Subject: [PATCH 06/83] fix support on builder update --- src/Eloquent/Builder.php | 23 +++++++++-------------- src/Eloquent/PostgisTrait.php | 2 +- 2 files changed, 10 insertions(+), 15 deletions(-) diff --git a/src/Eloquent/Builder.php b/src/Eloquent/Builder.php index 6e6b234..a6c4e12 100644 --- a/src/Eloquent/Builder.php +++ b/src/Eloquent/Builder.php @@ -9,26 +9,21 @@ public function update(array $values) { foreach ($values as $key => &$value) { if ($value instanceof GeometryInterface) { - $attrs = $this->getPostgisType($key); - $value = $this->asWKT($value, $attrs); + if (is_null($this->model)) { + $value = $this->asWKT($value); + } else { + $attrs = $this->model->getPostgisType($key); + $value = $this->model->asWKT($value, $attrs); + } } } return parent::update($values); } - protected function getPostgisFields() + protected function asWKT(GeometryInterface $geometry) { - return $this->getModel()->getPostgisFields(); - } - - protected function getPostgisType($key) - { - return $this->getModel()->getPostgisType($key); - } - - protected function asWKT(GeometryInterface $geometry, $attrs) - { - return $this->getModel()->asWKT($geometry, $attrs); + return $this->getQuery()->raw(sprintf("%s.ST_GeogFromText('%s')", + function_exists('config') ? config('postgis.schema') : 'public', $geometry->toWKT())); } } diff --git a/src/Eloquent/PostgisTrait.php b/src/Eloquent/PostgisTrait.php index 59791f6..dce7e4e 100644 --- a/src/Eloquent/PostgisTrait.php +++ b/src/Eloquent/PostgisTrait.php @@ -36,7 +36,7 @@ protected function geomFromText(GeometryInterface $geometry, $srid = 4326) function_exists('config') ? config('postgis.schema') : 'public', $geometry->toWKT(), $srid)); } - protected function asWKT(GeometryInterface $geometry, $attrs) + public function asWKT(GeometryInterface $geometry, $attrs) { switch (strtoupper($attrs['geomtype'])) { case 'GEOMETRY': From 26f96fe44b920a450b6f3dae29aa575b08a30432 Mon Sep 17 00:00:00 2001 From: Vinzenz Rosenkranz Date: Tue, 31 Jul 2018 20:41:20 +0200 Subject: [PATCH 07/83] add third dimension to all simple types --- src/Geometries/Factory.php | 2 +- src/Geometries/Geometry.php | 12 ++++++++ src/Geometries/LineString.php | 10 ++++++- src/Geometries/MultiLineString.php | 10 ++++++- src/Geometries/MultiPoint.php | 10 ++++++- src/Geometries/MultiPolygon.php | 10 ++++++- src/Geometries/Point.php | 46 ++++++++++++++++++++++++------ src/Geometries/Polygon.php | 9 +++++- 8 files changed, 95 insertions(+), 14 deletions(-) diff --git a/src/Geometries/Factory.php b/src/Geometries/Factory.php index f13f861..f5aca60 100644 --- a/src/Geometries/Factory.php +++ b/src/Geometries/Factory.php @@ -3,7 +3,7 @@ class Factory implements \GeoIO\Factory { public function createPoint( $dimension, array $coordinates, $srid = null ) { - return new Point( $coordinates['y'], $coordinates['x'] ); + return new Point( $coordinates['y'], $coordinates['x'], isset($coordinates['z']) ? $coordinates['z'] : null ); } public function createLineString( $dimension, array $points, $srid = null ) diff --git a/src/Geometries/Geometry.php b/src/Geometries/Geometry.php index 22316d2..f426150 100644 --- a/src/Geometries/Geometry.php +++ b/src/Geometries/Geometry.php @@ -30,16 +30,28 @@ public static function getWKTClass($value) switch (strtoupper($type)) { case 'POINT': + case 'POINTZ': + case 'POINT Z': return Point::class; case 'LINESTRING': + case 'LINESTRINGZ': + case 'LINESTRING Z': return LineString::class; case 'POLYGON': + case 'POLYGONZ': + case 'POLYGON Z': return Polygon::class; case 'MULTIPOINT': + case 'MULTIPOINTZ': + case 'MULTIPOINT Z': return MultiPoint::class; case 'MULTILINESTRING': + case 'MULTILINESTRINGZ': + case 'MULTILINESTRING Z': return MultiLineString::class; case 'MULTIPOLYGON': + case 'MULTIPOLYGONZ': + case 'MULTIPOLYGON Z': return MultiPolygon::class; case 'GEOMETRYCOLLECTION': return GeometryCollection::class; diff --git a/src/Geometries/LineString.php b/src/Geometries/LineString.php index effc1f4..4245a72 100644 --- a/src/Geometries/LineString.php +++ b/src/Geometries/LineString.php @@ -2,9 +2,17 @@ class LineString extends PointCollection implements GeometryInterface { + public function is3d() + { + if(count($this->points) === 0) return false; + return $this->points[0]->is3d(); + } + public function toWKT() { - return sprintf('LINESTRING(%s)', $this->toPairList()); + $wktType = 'LINESTRING'; + if($this->is3d()) $wktType .= ' Z'; + return sprintf('%s(%s)', $wktType, $this->toPairList()); } public static function fromWKT($wkt) diff --git a/src/Geometries/MultiLineString.php b/src/Geometries/MultiLineString.php index 75ee891..944c6eb 100644 --- a/src/Geometries/MultiLineString.php +++ b/src/Geometries/MultiLineString.php @@ -35,9 +35,17 @@ public function getLineStrings() return $this->linestrings; } + public function is3d() + { + if(count($this->linestrings) === 0) return false; + return $this->linestrings[0]->is3d(); + } + public function toWKT() { - return sprintf('MULTILINESTRING(%s)', (string)$this); + $wktType = 'MULTILINESTRING'; + if($this->is3d()) $wktType .= ' Z'; + return sprintf('%s(%s)', $wktType, (string)$this); } public static function fromString($wktArgument) diff --git a/src/Geometries/MultiPoint.php b/src/Geometries/MultiPoint.php index 17f423e..75a8b80 100644 --- a/src/Geometries/MultiPoint.php +++ b/src/Geometries/MultiPoint.php @@ -2,9 +2,17 @@ class MultiPoint extends PointCollection implements GeometryInterface, \JsonSerializable { + public function is3d() + { + if(count($this->points) === 0) return false; + return $this->points[0]->is3d(); + } + public function toWKT() { - return sprintf('MULTIPOINT(%s)', (string)$this); + $wktType = 'MULTIPOINT'; + if($this->is3d()) $wktType .= ' Z'; + return sprintf('%s(%s)', $wktType, (string)$this); } public static function fromWKT($wkt) diff --git a/src/Geometries/MultiPolygon.php b/src/Geometries/MultiPolygon.php index 62c331a..c016378 100644 --- a/src/Geometries/MultiPolygon.php +++ b/src/Geometries/MultiPolygon.php @@ -25,9 +25,17 @@ public function __construct(array $polygons) $this->polygons = $polygons; } + public function is3d() + { + if(count($this->polygons) === 0) return false; + return $this->polygons[0]->is3d(); + } + public function toWKT() { - return sprintf('MULTIPOLYGON(%s)', (string) $this); + $wktType = 'MULTIPOLYGON'; + if($this->is3d()) $wktType .= ' Z'; + return sprintf('%s(%s)', (string) $this); } public function __toString() diff --git a/src/Geometries/Point.php b/src/Geometries/Point.php index 559e3c0..0d1d50b 100644 --- a/src/Geometries/Point.php +++ b/src/Geometries/Point.php @@ -6,11 +6,13 @@ class Point extends Geometry { protected $lat; protected $lng; + protected $alt; - public function __construct($lat, $lng) + public function __construct($lat, $lng, $alt = null) { $this->lat = (float)$lat; $this->lng = (float)$lng; + $this->alt = isset($alt) ? (float)$alt : null; } public function getLat() @@ -33,28 +35,54 @@ public function setLng($lng) $this->lng = (float)$lng; } + public function getAlt() + { + return $this->alt; + } + + public function setLng($alt) + { + $this->alt = (float)$alt; + } + + public function is3d() + { + return isset($this->alt); + } + public function toPair() { - return self::stringifyFloat($this->getLng()) . ' ' . self::stringifyFloat($this->getLat()); + $pair = self::stringifyFloat($this->getLng()) . ' ' . self::stringifyFloat($this->getLat()); + if($this->is3d()) { + $pair .= ' ' . self::stringifyFloat($this->getAlt()); + } + return $pair; } - + private static function stringifyFloat($float) { // normalized output among locales return rtrim(rtrim(sprintf('%F', $float), '0'), '.'); } - + public static function fromPair($pair) { $pair = preg_replace('/^[a-zA-Z\(\)]+/', '', trim($pair)); - list($lng, $lat) = explode(' ', trim($pair)); + $splits = explode(' ', trim($pair)); + $lng = $splits[0]; + $lat = $splits[1]; + if(count($splits) > 2) { + $alt = $splits[2]; + } - return new static((float)$lat, (float)$lng); + return new static((float)$lat, (float)$lng, isset($alt) ? (float)$alt : null); } public function toWKT() { - return sprintf('POINT(%s)', (string)$this); + $wktType = 'POINT'; + if($this->is3d()) $wktType .= ' Z'; + return sprintf('%s(%s)', $wktType, (string)$this); } public static function fromString($wktArgument) @@ -74,6 +102,8 @@ public function __toString() */ public function jsonSerialize() { - return new \GeoJson\Geometry\Point([$this->getLng(), $this->getLat()]); + $position = [$this->getLng(), $this->getLat()]; + if($this->is3d()) $position[] = $this->getAlt(); + return new \GeoJson\Geometry\Point($position); } } diff --git a/src/Geometries/Polygon.php b/src/Geometries/Polygon.php index 2169d3d..dfe8cfc 100644 --- a/src/Geometries/Polygon.php +++ b/src/Geometries/Polygon.php @@ -4,10 +4,17 @@ class Polygon extends MultiLineString implements Countable { + public function is3d() + { + if(count($this->linestrings) === 0) return false; + return $this->linestrings[0]->is3d(); + } public function toWKT() { - return sprintf('POLYGON(%s)', (string)$this); + $wktType = 'POLYGON'; + if($this->is3d()) $wktType .= ' Z'; + return sprintf('%s(%s)', $wktType, (string)$this); } /** From 1055ccd1b772492374a2fdf2a0bfea9816494c6e Mon Sep 17 00:00:00 2001 From: Vinzenz Rosenkranz Date: Tue, 31 Jul 2018 20:55:47 +0200 Subject: [PATCH 08/83] fix copy&waste --- src/Geometries/Point.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Geometries/Point.php b/src/Geometries/Point.php index 0d1d50b..8b09473 100644 --- a/src/Geometries/Point.php +++ b/src/Geometries/Point.php @@ -40,7 +40,7 @@ public function getAlt() return $this->alt; } - public function setLng($alt) + public function setAlt($alt) { $this->alt = (float)$alt; } From c6fdfe7a5a35191a35c9bed053805424ae7ff9c5 Mon Sep 17 00:00:00 2001 From: Vinzenz Rosenkranz Date: Tue, 31 Jul 2018 21:02:15 +0200 Subject: [PATCH 09/83] add missing parameter --- src/Geometries/MultiPolygon.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Geometries/MultiPolygon.php b/src/Geometries/MultiPolygon.php index c016378..c97499c 100644 --- a/src/Geometries/MultiPolygon.php +++ b/src/Geometries/MultiPolygon.php @@ -35,7 +35,7 @@ public function toWKT() { $wktType = 'MULTIPOLYGON'; if($this->is3d()) $wktType .= ' Z'; - return sprintf('%s(%s)', (string) $this); + return sprintf('%s(%s)', $wktType, (string) $this); } public function __toString() From 8481a9b97c3ee274a5c99854d034b776d86a0b42 Mon Sep 17 00:00:00 2001 From: Vinzenz Rosenkranz Date: Wed, 1 Aug 2018 12:35:33 +0200 Subject: [PATCH 10/83] fix regex for 3d --- src/Geometries/MultiPoint.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Geometries/MultiPoint.php b/src/Geometries/MultiPoint.php index 75a8b80..96c08c4 100644 --- a/src/Geometries/MultiPoint.php +++ b/src/Geometries/MultiPoint.php @@ -25,7 +25,7 @@ public static function fromWKT($wkt) public static function fromString($wktArgument) { $matches = []; - preg_match_all('/\(\s*(\d+\s+\d+)\s*\)/', trim($wktArgument), $matches); + preg_match_all('/\(\s*(\d+\s+\d+(\s+\d+)?)\s*\)/', trim($wktArgument), $matches); if (count($matches) < 2) { return new static([]); From d5c86b1a6ee72d9f43515548af7a03f396e58e4f Mon Sep 17 00:00:00 2001 From: Vinzenz Rosenkranz Date: Wed, 1 Aug 2018 12:35:41 +0200 Subject: [PATCH 11/83] add 3d tests --- tests/Geometries/GeometryTest.php | 64 ++++++++++++++++++ tests/Geometries/LineStringTest.php | 32 +++++++++ tests/Geometries/MultiLineStringTest.php | 29 ++++++++- tests/Geometries/MultiPointTest.php | 26 ++++++++ tests/Geometries/MultiPolygonTest.php | 82 ++++++++++++++++++++++++ tests/Geometries/PointTest.php | 63 ++++++++++++++++++ tests/Geometries/PolygonTest.php | 38 +++++++++++ 7 files changed, 332 insertions(+), 2 deletions(-) diff --git a/tests/Geometries/GeometryTest.php b/tests/Geometries/GeometryTest.php index 3c0bd7e..58c13c0 100644 --- a/tests/Geometries/GeometryTest.php +++ b/tests/Geometries/GeometryTest.php @@ -43,6 +43,38 @@ public function testGetWKTArgument() ); } + public function testGetWKTArgument3d() + { + $this->assertEquals( + '1 1 1', + Geometry::getWKTArgument('POINT Z(1 1 1)') + ); + $this->assertEquals( + '1 1 1,1 2 2,2 2 3', + Geometry::getWKTArgument('LINESTRING Z(1 1 1,1 2 2,2 2 3)') + ); + $this->assertEquals( + '(1 1 1,4 1 1,4 4 1,1 4 1,1 1 1),(1 1 2, 2 1 2, 2 2 2, 1 2 2,1 1 2)', + Geometry::getWKTArgument('POLYGON Z((1 1 1,4 1 1,4 4 1,1 4 1,1 1 1),(1 1 2, 2 1 2, 2 2 2, 1 2 2,1 1 2))') + ); + $this->assertEquals( + '(1 1 1),(1 2 2)', + Geometry::getWKTArgument('MULTIPOINT Z((1 1 1),(1 2 2))') + ); + $this->assertEquals( + '(1 1 1,1 2 1,2 2 1),(2 3 2,3 2 2,5 4 2)', + Geometry::getWKTArgument('MULTILINESTRING Z((1 1 1,1 2 1,2 2 1),(2 3 2,3 2 2,5 4 2))') + ); + $this->assertEquals( + '((1 1 1,4 1 1,4 4 1,1 4 1,1 1 1),(1 1 2,2 1 2,2 2 2,1 2 2,1 1 2)), ((-1 -1 -1,-1 -2 -1,-2 -2 -1,-2 -1 -1,-1 -1 -1))', + Geometry::getWKTArgument('MULTIPOLYGON Z(((1 1 1,4 1 1,4 4 1,1 4 1,1 1 1),(1 1 2,2 1 2,2 2 2,1 2 2,1 1 2)), ((-1 -1 -1,-1 -2 -1,-2 -2 -1,-2 -1 -1,-1 -1 -1)))') + ); + $this->assertEquals( + 'POINT Z(2 3 4),LINESTRING Z(2 3 4,3 4 5)', + Geometry::getWKTArgument('GEOMETRYCOLLECTION(POINT Z(2 3 4),LINESTRING Z(2 3 4,3 4 5))') + ); + } + public function testGetWKTClass() { $this->assertEquals( @@ -75,6 +107,38 @@ public function testGetWKTClass() ); } + public function testGetWKTClass3d() + { + $this->assertEquals( + Point::class, + Geometry::getWKTClass('POINT Z(0 0 0)') + ); + $this->assertEquals( + LineString::class, + Geometry::getWKTClass('LINESTRING Z(0 0 0,1 1 1,1 2 3)') + ); + $this->assertEquals( + Polygon::class, + Geometry::getWKTClass('POLYGON Z((0 0 0 ,4 0 3,4 4 4,0 4 0,0 0 0),(1 1 1, 2 1 2, 2 2 2, 1 2 2,1 1 1))') + ); + $this->assertEquals( + MultiPoint::class, + Geometry::getWKTClass('MULTIPOINT Z((0 00),(1 2 3))') + ); + $this->assertEquals( + MultiLineString::class, + Geometry::getWKTClass('MULTILINESTRING Z((0 0 0 ,1 1 1,1 2 3),(2 3 4,3 2 1,5 4 3))') + ); + $this->assertEquals( + MultiPolygon::class, + Geometry::getWKTClass('MULTIPOLYGON Z(((0 0 0,4 0 4,4 4 4,0 4 0,0 0 0),(1 1 1,2 1 2,2 2 2,1 2 2,1 1 1)), ((-1 -1 -1,-1 -2 -1,-2 -2 -1,-2 -1 -1,-1 -1 -1)))') + ); + $this->assertEquals( + GeometryCollection::class, + Geometry::getWKTClass('GEOMETRYCOLLECTION(POINT Z(2 3 4),LINESTRING Z(2 3 4,3 4 5))') + ); + } + public function testGetWKBClass() { $this->assertInstanceOf( diff --git a/tests/Geometries/LineStringTest.php b/tests/Geometries/LineStringTest.php index de69ed1..3398ef4 100644 --- a/tests/Geometries/LineStringTest.php +++ b/tests/Geometries/LineStringTest.php @@ -6,10 +6,12 @@ class LineStringTest extends BaseTestCase { private $points; + private $points3d; protected function setUp() { $this->points = [new Point(1, 1), new Point(2, 2), new Point(3, 3)]; + $this->points3d = [new Point(1, 1, 1), new Point(2, 2, 2), new Point(3, 3, 3)]; } public function testToWKT() @@ -19,6 +21,13 @@ public function testToWKT() $this->assertEquals('LINESTRING(1 1,2 2,3 3)', $linestring->toWKT()); } + public function testToWKT3d() + { + $linestring = new LineString($this->points3d); + + $this->assertEquals('LINESTRING Z(1 1 1,2 2 2,3 3 3)', $linestring->toWKT()); + } + public function testFromWKT() { $linestring = LineString::fromWKT('LINESTRING(1 1, 2 2,3 3)'); @@ -27,6 +36,14 @@ public function testFromWKT() $this->assertEquals(3, $linestring->count()); } + public function testFromWKT3d() + { + $linestring = LineString::fromWKT('LINESTRING Z(1 1 1, 2 2 2,3 3 3)'); + $this->assertInstanceOf(LineString::class, $linestring); + + $this->assertEquals(3, $linestring->count()); + } + public function testToString() { $linestring = new LineString($this->points); @@ -34,6 +51,13 @@ public function testToString() $this->assertEquals('1 1,2 2,3 3', (string)$linestring); } + public function testToString3d() + { + $linestring = new LineString($this->points3d); + + $this->assertEquals('1 1 1,2 2 2,3 3 3', (string)$linestring); + } + public function testJsonSerialize() { $lineString = new LineString($this->points); @@ -41,4 +65,12 @@ public function testJsonSerialize() $this->assertInstanceOf(\GeoJson\Geometry\LineString::class, $lineString->jsonSerialize()); $this->assertSame('{"type":"LineString","coordinates":[[1,1],[2,2],[3,3]]}', json_encode($lineString)); } + + public function testJsonSerialize3d() + { + $lineString = new LineString($this->points3d); + + $this->assertInstanceOf(\GeoJson\Geometry\LineString::class, $lineString->jsonSerialize()); + $this->assertSame('{"type":"LineString","coordinates":[[1,1,1],[2,2,2],[3,3,3]]}', json_encode($lineString)); + } } diff --git a/tests/Geometries/MultiLineStringTest.php b/tests/Geometries/MultiLineStringTest.php index cdaa757..0c312b2 100644 --- a/tests/Geometries/MultiLineStringTest.php +++ b/tests/Geometries/MultiLineStringTest.php @@ -14,6 +14,14 @@ public function testFromWKT() $this->assertSame(2, $multilinestring->count()); } + public function testFromWKT3d() + { + $multilinestring = MultiLineString::fromWKT('MULTILINESTRING Z((1 1 1,2 2 2,2 3 4),(3 4 5,4 3 2,6 5 4))'); + $this->assertInstanceOf(MultiLineString::class, $multilinestring); + + $this->assertSame(2, $multilinestring->count()); + } + public function testToWKT() { $collection = new LineString( @@ -31,13 +39,30 @@ public function testToWKT() $this->assertSame('MULTILINESTRING((1 1,2 1,2 2,1 2,1 1))', $multilinestring->toWKT()); } + public function testToWKT3d() + { + $collection = new LineString( + [ + new Point(1, 1, 1), + new Point(1, 2, 3), + new Point(2, 2, 2), + new Point(2, 1, 3), + new Point(1, 1, 1) + ] + ); + + $multilinestring = new MultiLineString([$collection]); + + $this->assertSame('MULTILINESTRING Z((1 1 1,2 1 3,2 2 2,1 2 3,1 1 1))', $multilinestring->toWKT()); + } + public function testJsonSerialize() { - $multilinestring = MultiLineString::fromWKT('MULTILINESTRING((1 1,2 2,2 3),(3 4,4 3,6 5))'); + $multilinestring = MultiLineString::fromWKT('MULTILINESTRING Z((1 1 1,2 2 2,2 3 4),(3 4 5,4 3 2,6 5 4))'); $this->assertInstanceOf(\GeoJson\Geometry\MultiLineString::class, $multilinestring->jsonSerialize()); $this->assertSame( - '{"type":"MultiLineString","coordinates":[[[1,1],[2,2],[2,3]],[[3,4],[4,3],[6,5]]]}', + '{"type":"MultiLineString","coordinates":[[[1,1,1],[2,2,2],[2,3,4]],[[3,4,5],[4,3,2],[6,5,4]]]}', json_encode($multilinestring) ); } diff --git a/tests/Geometries/MultiPointTest.php b/tests/Geometries/MultiPointTest.php index 49c246a..00d8383 100644 --- a/tests/Geometries/MultiPointTest.php +++ b/tests/Geometries/MultiPointTest.php @@ -12,6 +12,13 @@ public function testFromWKT() $this->assertEquals(3, $multipoint->count()); } + public function testFromWKT3d() + { + $multipoint = MultiPoint::fromWKT('MULTIPOINT Z((1 1 1),(2 1 3),(2 2 2))'); + $this->assertInstanceOf(MultiPoint::class, $multipoint); + + $this->assertEquals(3, $multipoint->count()); + } public function testToWKT() { @@ -22,6 +29,15 @@ public function testToWKT() $this->assertEquals('MULTIPOINT((1 1),(2 1),(2 2))', $multipoint->toWKT()); } + public function testToWKT3d() + { + $collection = [new Point(1, 1, 1), new Point(1, 2, 3), new Point(2, 2, 2)]; + + $multipoint = new MultiPoint($collection); + + $this->assertEquals('MULTIPOINT Z((1 1 1),(2 1 3),(2 2 2))', $multipoint->toWKT()); + } + public function testJsonSerialize() { $collection = [new Point(1, 1), new Point(1, 2), new Point(2, 2)]; @@ -31,4 +47,14 @@ public function testJsonSerialize() $this->assertInstanceOf(\GeoJson\Geometry\MultiPoint::class, $multipoint->jsonSerialize()); $this->assertSame('{"type":"MultiPoint","coordinates":[[1,1],[2,1],[2,2]]}', json_encode($multipoint)); } + + public function testJsonSerialize3d() + { + $collection = [new Point(1, 1, 1), new Point(1, 2, 3), new Point(2, 2, 2)]; + + $multipoint = new MultiPoint($collection); + + $this->assertInstanceOf(\GeoJson\Geometry\MultiPoint::class, $multipoint->jsonSerialize()); + $this->assertSame('{"type":"MultiPoint","coordinates":[[1,1,1],[2,1,3],[2,2,2]]}', json_encode($multipoint)); + } } diff --git a/tests/Geometries/MultiPolygonTest.php b/tests/Geometries/MultiPolygonTest.php index 001d7e7..3844186 100644 --- a/tests/Geometries/MultiPolygonTest.php +++ b/tests/Geometries/MultiPolygonTest.php @@ -11,6 +11,7 @@ class MultiPolygonTest extends BaseTestCase * @var MultiPolygon */ private $multiPolygon; + private $multiPolygon3d; protected function setUp() { @@ -50,6 +51,43 @@ protected function setUp() $polygon2 = new Polygon([$collection3]); $this->multiPolygon = new MultiPolygon([$polygon1, $polygon2]); + + $collection1 = new LineString( + [ + new Point(1, 1, 1), + new Point(1, 2, 3), + new Point(2, 2, 2), + new Point(2, 1, 0), + new Point(1, 1, 1) + ] + ); + + $collection2 = new LineString( + [ + new Point(10, 10, 10), + new Point(10, 20, 30), + new Point(20, 20, 20), + new Point(20, 10, 0), + new Point(10, 10, 10) + ] + ); + + $polygon1 = new Polygon([$collection1, $collection2]); + + $collection3 = new LineString( + [ + new Point(100, 100, 100), + new Point(100, 200, 300), + new Point(200, 200, 200), + new Point(200, 100, 0), + new Point(100, 100, 100) + ] + ); + + + $polygon2 = new Polygon([$collection3]); + + $this->multiPolygon3d = new MultiPolygon([$polygon1, $polygon2]); } public function testFromWKT() @@ -62,6 +100,15 @@ public function testFromWKT() $this->assertEquals($wkt, $polygon->toWKT()); } + public function testFromWKT3d() + { + $wkt = 'MULTIPOLYGON Z(((1 1 1,2 1 3,2 2 2,1 2 0,1 1 1),(1 1 1,2 1 3,2 2 2,1 2 0,1 1)),((-1 -1 -1,-1 -2 -3,-2 -2 -2,-2 -1 0,-1 -1 -1)))'; + $polygon = MultiPolygon::fromWKT($wkt); + + $this->assertInstanceOf(MultiPolygon::class, $polygon); + $this->assertEquals(2, $polygon->count()); + $this->assertEquals($wkt, $polygon->toWKT()); + } public function testToWKT() { @@ -71,6 +118,14 @@ public function testToWKT() ); } + public function testToWKT3d() + { + $this->assertEquals( + 'MULTIPOLYGON Z(((1 1 1,2 1 3,2 2 2,1 2 0,1 1 1),(10 10 10,20 10 30,20 20 20,10 20 0,10 10 10)),((100 100 100,200 100 300,200 200 200,100 200 0,100 100 100)))', + $this->multiPolygon3d->toWKT() + ); + } + public function testGetPolygons() { $polygon = MultiPolygon::fromWKT( @@ -80,6 +135,15 @@ public function testGetPolygons() $this->assertInstanceOf(Polygon::class, $polygon->getPolygons()[0]); } + public function testGetPolygons3d() + { + $polygon = MultiPolygon::fromWKT( + 'MULTIPOLYGON Z(((0 0 0,4 0 0,4 4 4,0 4 0,0 0 0),(1 1 1,2 1 3,2 2 2,1 2 0,1 1 1)), ((-1 -1 -1,-1 -2 0,-2 -2 -2,-2 -1 -3,-1 -1 -1)))' + ); + + $this->assertInstanceOf(Polygon::class, $polygon->getPolygons()[0]); + } + public function testIssue12() { $polygon = MultiPolygon::fromWKT( @@ -89,6 +153,15 @@ public function testIssue12() $this->assertInstanceOf(MultiPolygon::class, $polygon); } + public function testIssue123d() + { + $polygon = MultiPolygon::fromWKT( + 'MULTIPOLYGON Z(((-80.214554 25.769598 0 0,-80.2147 25.774514 0 0,-80.212983 25.77456 0 0,-80.212977 25.773597 0 0,-80.211448 25.773655 0 0,-80.211498 25.774579 0 0,-80.209432 25.774665 0 0,-80.209392 25.773667 0 0,-80.204387 25.773834 0 0,-80.199383 25.774324 0 0,-80.197718 25.774031 0 0,-80.197757 25.774975 0 0,-80.193655 25.775108 0 0,-80.193623 25.774134 0 0,-80.191855 25.772551 0 0,-80.193442 25.76969 0 0,-80.192231 25.768345 0 0,-80.192879 25.758009 0 0,-80.196301 25.759985 0 0,-80.195608 25.76152 0 0,-80.198856 25.761454 0 0,-80.200646 25.763287 0 0,-80.20401 25.763164 0 0,-80.204023 25.76367 0 0,-80.205673 25.763141 0 0,-80.214326 25.762935 0 0,-80.214451 25.765883 0 0,-80.214539 25.768649 0 0,-80.216203 25.76858 0 0,-80.214554 25.769598 0 0)))' + ); + + $this->assertInstanceOf(MultiPolygon::class, $polygon); + } + public function testJsonSerialize() { $this->assertInstanceOf(\GeoJson\Geometry\MultiPolygon::class, $this->multiPolygon->jsonSerialize()); @@ -97,4 +170,13 @@ public function testJsonSerialize() json_encode($this->multiPolygon) ); } + + public function testJsonSerialize3d() + { + $this->assertInstanceOf(\GeoJson\Geometry\MultiPolygon::class, $this->multiPolygon3d->jsonSerialize()); + $this->assertSame( + '{"type":"MultiPolygon","coordinates":[[[[1,1,1],[2,1,3],[2,2,2],[1,2,0],[1,1,1]],[[10,10,10],[20,10,30],[20,20,20],[10,20,0],[10,10,10]]],[[[100,100,100],[200,100,300],[200,200,200],[100,200,0],[100,100,100]]]]}', + json_encode($this->multiPolygon3d) + ); + } } diff --git a/tests/Geometries/PointTest.php b/tests/Geometries/PointTest.php index f12ff09..290cd38 100644 --- a/tests/Geometries/PointTest.php +++ b/tests/Geometries/PointTest.php @@ -13,6 +13,16 @@ public function testFromWKT() $this->assertEquals(1, $point->getLng()); } + public function testFromWKT3d() + { + $point = Point::fromWKT('POINT(1 2 3)'); + + $this->assertInstanceOf(Point::class, $point); + $this->assertEquals(2, $point->getLat()); + $this->assertEquals(1, $point->getLng()); + $this->assertEquals(3, $point->getAlt()); + } + public function testToWKT() { $point = new Point(1, 2); @@ -20,6 +30,13 @@ public function testToWKT() $this->assertEquals('POINT(2 1)', $point->toWKT()); } + public function testToWKT3d() + { + $point = new Point(1, 2, 3); + + $this->assertEquals('POINT Z(2 1 3)', $point->toWKT()); + } + public function testGettersAndSetters() { $point = new Point(1, 2); @@ -33,6 +50,22 @@ public function testGettersAndSetters() $this->assertSame(4.0, $point->getLng()); } + public function testGettersAndSetters3d() + { + $point = new Point(1, 2, 3); + $this->assertSame(1.0, $point->getLat()); + $this->assertSame(2.0, $point->getLng()); + $this->assertSame(3.0, $point->getAlt()); + + $point->setLat('3'); + $point->setLng('4'); + $point->setAlt('5'); + + $this->assertSame(3.0, $point->getLat()); + $this->assertSame(4.0, $point->getLng()); + $this->assertSame(5.0, $point->getAlt()); + } + public function testPair() { $point = Point::fromPair('1.5 2'); @@ -43,6 +76,17 @@ public function testPair() $this->assertSame('1.5 2', $point->toPair()); } + public function testPair3d() + { + $point = Point::fromPair('1.5 2 2.5'); + + $this->assertSame(1.5, $point->getLng()); + $this->assertSame(2.0, $point->getLat()); + $this->assertSame(2.5, $point->getAlt()); + + $this->assertSame('1.5 2 2.5', $point->toPair()); + } + public function testToString() { $point = Point::fromString('1.3 2'); @@ -53,6 +97,17 @@ public function testToString() $this->assertEquals('1.3 2', (string)$point); } + public function testToString3d() + { + $point = Point::fromString('1.3 2 2.3'); + + $this->assertSame(1.3, $point->getLng()); + $this->assertSame(2.0, $point->getLat()); + $this->assertSame(2.3, $point->getAlt()); + + $this->assertEquals('1.3 2 2.3', (string)$point); + } + public function testJsonSerialize() { $point = new Point(1.2, 3.4); @@ -60,4 +115,12 @@ public function testJsonSerialize() $this->assertInstanceOf(\GeoJson\Geometry\Point::class, $point->jsonSerialize()); $this->assertSame('{"type":"Point","coordinates":[3.4,1.2]}', json_encode($point)); } + + public function testJsonSerialize3d() + { + $point = new Point(1.2, 3.4, 5.6); + + $this->assertInstanceOf(\GeoJson\Geometry\Point::class, $point->jsonSerialize()); + $this->assertSame('{"type":"Point","coordinates":[3.4,1.2,5.6]}', json_encode($point)); + } } diff --git a/tests/Geometries/PolygonTest.php b/tests/Geometries/PolygonTest.php index 6f71432..372880c 100644 --- a/tests/Geometries/PolygonTest.php +++ b/tests/Geometries/PolygonTest.php @@ -7,6 +7,7 @@ class PolygonTest extends BaseTestCase { private $polygon; + private $polygon3d; protected function setUp() { @@ -21,6 +22,18 @@ protected function setUp() ); $this->polygon = new Polygon([$collection]); + + $collection = new LineString( + [ + new Point(1, 1, 1), + new Point(1, 2, 2), + new Point(2, 2, 2), + new Point(2, 1, 2), + new Point(1, 1, 1) + ] + ); + + $this->polygon3d = new Polygon([$collection]); } @@ -34,11 +47,26 @@ public function testFromWKT() $this->assertEquals($wkt, $polygon->toWKT()); } + public function testFromWKT3d() + { + $wkt = 'POLYGON Z((1 1 1,5 1 1,5 5 1,1 5 1,1 1 1),(2 2 2,3 2 2,3 3 2,2 3 2,2 2 2))'; + $polygon = Polygon::fromWKT($wkt); + $this->assertInstanceOf(Polygon::class, $polygon); + + $this->assertEquals(2, $polygon->count()); + $this->assertEquals($wkt, $polygon->toWKT()); + } + public function testToWKT() { $this->assertEquals('POLYGON((1 1,2 1,2 2,1 2,1 1))', $this->polygon->toWKT()); } + public function testToWKT3d() + { + $this->assertEquals('POLYGON Z((1 1 1,2 1 2,2 2 2,1 2 2,1 1 1))', $this->polygon3d->toWKT()); + } + public function testJsonSerialize() { $this->assertInstanceOf(\GeoJson\Geometry\Polygon::class, $this->polygon->jsonSerialize()); @@ -48,4 +76,14 @@ public function testJsonSerialize() ); } + + public function testJsonSerialize3d() + { + $this->assertInstanceOf(\GeoJson\Geometry\Polygon::class, $this->polygon3d->jsonSerialize()); + $this->assertSame( + '{"type":"Polygon","coordinates":[[[1,1,1],[2,1,2],[2,2,2],[1,2,2],[1,1,1]]]}', + json_encode($this->polygon3d) + ); + + } } From 1a691ea5f99dc2560773304ab726ccc0b09876a2 Mon Sep 17 00:00:00 2001 From: Vinzenz Rosenkranz Date: Wed, 1 Aug 2018 13:01:42 +0200 Subject: [PATCH 12/83] add more tests --- tests/Eloquent/BuilderTest.php | 45 +++++++++++++++++++ tests/Eloquent/PostgisTraitTest.php | 25 +++++++++++ tests/Geometries/GeometryCollectionTest.php | 50 +++++++++++++++++++++ 3 files changed, 120 insertions(+) diff --git a/tests/Eloquent/BuilderTest.php b/tests/Eloquent/BuilderTest.php index 1b05985..ed8ac4d 100644 --- a/tests/Eloquent/BuilderTest.php +++ b/tests/Eloquent/BuilderTest.php @@ -86,6 +86,51 @@ public function testUpdateLinestring() $builder->update(['linestring' => $linestring]); } + + public function testUpdate3d() + { + $this->queryBuilder + ->shouldReceive('raw') + ->with("public.ST_GeogFromText('POINT Z(2 1 0)')") + ->andReturn(new Expression("public.ST_GeogFromText('POINT Z(2 1 0)')")); + + $this->queryBuilder + ->shouldReceive('update') + ->andReturn(1); + + $builder = m::mock(Builder::class, [$this->queryBuilder])->makePartial(); + $builder->shouldAllowMockingProtectedMethods(); + $builder + ->shouldReceive('addUpdatedAtColumn') + ->andReturn(['point' => new Point(1, 2, 0)]); + + $builder->update(['point' => new Point(1, 2, 0)]); + } + + public function testUpdateLinestring3d() + { + $this->queryBuilder + ->shouldReceive('raw') + ->with("public.ST_GeogFromText('LINESTRING Z(0 0 0, 1 1 1, 2 2 2)')") + ->andReturn(new Expression("public.ST_GeogFromText('LINESTRING Z(0 0 0, 1 1 1, 2 2 2)')")); + + $this->queryBuilder + ->shouldReceive('update') + ->andReturn(1); + + $linestring = new LineString([new Point(0, 0, 0), new Point(1, 1, 1), new Point(2, 2, 2)]); + + $builder = m::mock(Builder::class, [$this->queryBuilder])->makePartial(); + $builder->shouldAllowMockingProtectedMethods(); + $builder + ->shouldReceive('addUpdatedAtColumn') + ->andReturn(['linestring' => $linestring]); + + $builder + ->shouldReceive('asWKT')->with($linestring)->once(); + + $builder->update(['linestring' => $linestring]); + } } class TestBuilderModel extends Model diff --git a/tests/Eloquent/PostgisTraitTest.php b/tests/Eloquent/PostgisTraitTest.php index 2cd2487..54ab05a 100644 --- a/tests/Eloquent/PostgisTraitTest.php +++ b/tests/Eloquent/PostgisTraitTest.php @@ -53,6 +53,31 @@ public function testUpdatePointHasCorrectSql() $this->assertContains("public.ST_GeogFromText('POINT(4 2)')", $this->queries[0]); } + + public function testInsertPoint3dHasCorrectSql() + { + $this->model->point = new Point(1, 2, 3); + $this->model->save(); + + $this->assertContains("public.ST_GeogFromText('POINT Z(2 1 3)')", $this->queries[0]); + } + + public function testInsertPoint3dGeometryHasCorrectSql() + { + $this->model->point2 = new Point(1, 2, 3); + $this->model->save(); + + $this->assertContains("public.ST_GeomFromText('POINT Z(2 1 3)', '27700')", $this->queries[0]); + } + + public function testUpdatePoint3dHasCorrectSql() + { + $this->model->exists = true; + $this->model->point = new Point(2, 4, 6); + $this->model->save(); + + $this->assertContains("public.ST_GeogFromText('POINT Z(4 2 6)')", $this->queries[0]); + } } class TestModel extends Model diff --git a/tests/Geometries/GeometryCollectionTest.php b/tests/Geometries/GeometryCollectionTest.php index f98b0c6..3f91a0f 100644 --- a/tests/Geometries/GeometryCollectionTest.php +++ b/tests/Geometries/GeometryCollectionTest.php @@ -10,6 +10,7 @@ class GeometryCollectionTest extends BaseTestCase * @var GeometryCollection */ private $collection; + private $collection3d; protected function setUp() { @@ -26,6 +27,20 @@ protected function setUp() $point = new Point(100, 200); $this->collection = new GeometryCollection([$collection, $point]); + + $collection = new LineString( + [ + new Point(1, 1, 1), + new Point(1, 2, 3), + new Point(2, 2, 2), + new Point(2, 1, 0), + new Point(1, 1, 1) + ] + ); + + $point = new Point(100, 200, 300); + + $this->collection3d = new GeometryCollection([$collection, $point]); } @@ -42,6 +57,19 @@ public function testFromWKT() $this->assertInstanceOf(LineString::class, $geometryCollection->getGeometries()[1]); } + public function testFromWKT3d() + { + /** + * @var GeometryCollection $geometryCollection + */ + $geometryCollection = GeometryCollection::fromWKT('GEOMETRYCOLLECTION(POINT Z(2 3 4),LINESTRING Z(2 3 4,3 4 5))'); + $this->assertInstanceOf(GeometryCollection::class, $geometryCollection); + + $this->assertEquals(2, $geometryCollection->count()); + $this->assertInstanceOf(Point::class, $geometryCollection->getGeometries()[0]); + $this->assertInstanceOf(LineString::class, $geometryCollection->getGeometries()[1]); + } + public function testToWKT() { $this->assertEquals( @@ -50,6 +78,14 @@ public function testToWKT() ); } + public function testToWKT3d() + { + $this->assertEquals( + 'GEOMETRYCOLLECTION(LINESTRING Z(1 1 1,2 1 3,2 2 2,1 2 0,1 1 1),POINT Z(200 100 300))', + $this->collection3d->toWKT() + ); + } + public function testJsonSerialize() { $this->assertInstanceOf( @@ -63,4 +99,18 @@ public function testJsonSerialize() ); } + + public function testJsonSerialize3d() + { + $this->assertInstanceOf( + \GeoJson\Geometry\GeometryCollection::class, + $this->collection3d->jsonSerialize() + ); + + $this->assertSame( + '{"type":"GeometryCollection","geometries":[{"type":"LineString","coordinates":[[1,1,1],[2,1,3],[2,2,2],[1,2,0],[1,1,1]]},{"type":"Point","coordinates":[200,100,300]}]}', + json_encode($this->collection3d->jsonSerialize()) + ); + + } } From 5ee418e9972d693f53f90bd3b4c43880e63bb772 Mon Sep 17 00:00:00 2001 From: Nick Barrett Date: Wed, 6 Mar 2019 08:46:18 +0800 Subject: [PATCH 13/83] :fire: remove hhvm support --- .travis.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 1a42468..8c3bb98 100644 --- a/.travis.yml +++ b/.travis.yml @@ -4,7 +4,6 @@ php: - 5.5 - 5.6 - 7.0 - - hhvm - nightly matrix: allow_failures: From c0a47a9b94c67db57b479e3271951e09fb32c993 Mon Sep 17 00:00:00 2001 From: Nick Barrett Date: Wed, 6 Mar 2019 08:47:04 +0800 Subject: [PATCH 14/83] :construction_worker: test against php 7.1, 7.2, 7.3 --- .travis.yml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.travis.yml b/.travis.yml index 8c3bb98..537c1ae 100644 --- a/.travis.yml +++ b/.travis.yml @@ -4,6 +4,9 @@ php: - 5.5 - 5.6 - 7.0 + - 7.1 + - 7.2 + - 7.3 - nightly matrix: allow_failures: From 36db592197b1c5b7a4f48db0baa22d69525b88ae Mon Sep 17 00:00:00 2001 From: Nick Barrett Date: Wed, 6 Mar 2019 11:07:02 +0800 Subject: [PATCH 15/83] :green_heart: allow failures in nightly --- .travis.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 537c1ae..062e2ba 100644 --- a/.travis.yml +++ b/.travis.yml @@ -8,9 +8,10 @@ php: - 7.2 - 7.3 - nightly + matrix: allow_failures: - - nightly + - php: nightly install: - travis_retry composer install From 0a10f6d0083ebb2140c97e1d8e7e533fe4e1e2f2 Mon Sep 17 00:00:00 2001 From: Nick Barrett Date: Wed, 6 Mar 2019 11:16:08 +0800 Subject: [PATCH 16/83] :memo: update README with version info --- README.md | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 6783bf4..fb08e5a 100644 --- a/README.md +++ b/README.md @@ -16,10 +16,7 @@ Laravel postgis extension ## Versions - Use 2.* for Laravel 5.1.* -- Use 3.* for Laravel 5.2.* -- Use 3.* for Laravel 5.3.* -- Use 3.* for Laravel 5.4.* -- Use 3.* for Laravel 5.5.* +- Use 3.* for Laravel > 5.2 ## Installation @@ -137,7 +134,7 @@ class Location extends Model 'polygon', 'polygon2' ]; - + protected $postgisTypes = [ 'location' => [ 'geomtype' => 'geography', From 2f74c7b4d257d0494c6e52d93f70e29d30d1335f Mon Sep 17 00:00:00 2001 From: Nick Barrett Date: Thu, 21 Mar 2019 09:21:48 +0800 Subject: [PATCH 17/83] :bug: fix issue with multipoints only containing one point --- src/Geometries/MultiPoint.php | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/src/Geometries/MultiPoint.php b/src/Geometries/MultiPoint.php index 96c08c4..8013363 100644 --- a/src/Geometries/MultiPoint.php +++ b/src/Geometries/MultiPoint.php @@ -2,6 +2,23 @@ class MultiPoint extends PointCollection implements GeometryInterface, \JsonSerializable { + /** + * @param Point[] $points + */ + public function __construct(array $points) + { + if (count($points) < 1) { + throw new InvalidArgumentException('$points must contain at least one entry'); + } + $validated = array_filter($points, function ($value) { + return $value instanceof Point; + }); + if (count($points) !== count($validated)) { + throw new InvalidArgumentException('$points must be an array of Points'); + } + $this->points = $points; + } + public function is3d() { if(count($this->points) === 0) return false; From ff4ff60b05c9b3e9caa58992b4c5eaa5f0b69ff6 Mon Sep 17 00:00:00 2001 From: Chrudos Vorlicek Date: Tue, 16 Jul 2019 10:12:47 +0200 Subject: [PATCH 18/83] Fix creation of geometry outside public schema --- src/Schema/Grammars/PostgisGrammar.php | 102 ++++++++++--------------- 1 file changed, 40 insertions(+), 62 deletions(-) diff --git a/src/Schema/Grammars/PostgisGrammar.php b/src/Schema/Grammars/PostgisGrammar.php index f6b403d..e3a0733 100644 --- a/src/Schema/Grammars/PostgisGrammar.php +++ b/src/Schema/Grammars/PostgisGrammar.php @@ -18,15 +18,7 @@ class PostgisGrammar extends PostgresGrammar */ public function typePoint(Fluent $column) { - $type = strtoupper($column->geomtype); - if ($this->isValid($column)) { - if ($type == 'GEOGRAPHY' && $column->srid != 4326) { - throw new UnsupportedGeomtypeException('Error with validation of srid! SRID of GEOGRAPHY must be 4326)'); - } - return $type . '(POINT, ' . $column->srid . ')'; - } else { - throw new UnsupportedGeomtypeException('Error with validation of geom type or srid!'); - } + return $this->createTypeDefinition($column, 'POINT'); } /** @@ -37,15 +29,7 @@ public function typePoint(Fluent $column) */ public function typeMultipoint(Fluent $column) { - $type = strtoupper($column->geomtype); - if ($this->isValid($column)) { - if ($type == 'GEOGRAPHY' && $column->srid != 4326) { - throw new UnsupportedGeomtypeException('Error with validation of srid! SRID of GEOGRAPHY must be 4326)'); - } - return strtoupper($column->geomtype) . '(MULTIPOINT, ' . $column->srid . ')'; - } else { - throw new UnsupportedGeomtypeException('Error with validation of geom type or srid!'); - } + return $this->createTypeDefinition($column, 'MULTIPOINT'); } /** @@ -56,15 +40,7 @@ public function typeMultipoint(Fluent $column) */ public function typePolygon(Fluent $column) { - $type = strtoupper($column->geomtype); - if ($this->isValid($column)) { - if ($type == 'GEOGRAPHY' && $column->srid != 4326) { - throw new UnsupportedGeomtypeException('Error with validation of srid! SRID of GEOGRAPHY must be 4326)'); - } - return strtoupper($column->geomtype) . '(POLYGON, ' . $column->srid . ')'; - } else { - throw new UnsupportedGeomtypeException('Error with validation of geom type or srid!'); - } + return $this->createTypeDefinition($column, 'POLYGON'); } /** @@ -75,15 +51,7 @@ public function typePolygon(Fluent $column) */ public function typeMultipolygon(Fluent $column) { - $type = strtoupper($column->geomtype); - if ($this->isValid($column)) { - if ($type == 'GEOGRAPHY' && $column->srid != 4326) { - throw new UnsupportedGeomtypeException('Error with validation of srid! SRID of GEOGRAPHY must be 4326)'); - } - return strtoupper($column->geomtype) . '(MULTIPOLYGON, ' . $column->srid . ')'; - } else { - throw new UnsupportedGeomtypeException('Error with validation of geom type or srid!'); - } + return $this->createTypeDefinition($column, 'MULTIPOLYGON'); } /** @@ -94,15 +62,7 @@ public function typeMultipolygon(Fluent $column) */ public function typeLinestring(Fluent $column) { - $type = strtoupper($column->geomtype); - if ($this->isValid($column)) { - if ($type == 'GEOGRAPHY' && $column->srid != 4326) { - throw new UnsupportedGeomtypeException('Error with validation of srid! SRID of GEOGRAPHY must be 4326)'); - } - return strtoupper($column->geomtype) . '(LINESTRING, ' . $column->srid . ')'; - } else { - throw new UnsupportedGeomtypeException('Error with validation of geom type or srid!'); - } + return $this->createTypeDefinition($column, 'LINESTRING'); } /** @@ -113,15 +73,7 @@ public function typeLinestring(Fluent $column) */ public function typeMultilinestring(Fluent $column) { - $type = strtoupper($column->geomtype); - if ($this->isValid($column)) { - if ($type == 'GEOGRAPHY' && $column->srid != 4326) { - throw new UnsupportedGeomtypeException('Error with validation of srid! SRID of GEOGRAPHY must be 4326)'); - } - return strtoupper($column->geomtype) . '(MULTILINESTRING, ' . $column->srid . ')'; - } else { - throw new UnsupportedGeomtypeException('Error with validation of geom type or srid!'); - } + return $this->createTypeDefinition($column, 'MULTILINESTRING'); } /** @@ -193,15 +145,18 @@ protected function compileGeometry(Blueprint $blueprint, Fluent $command) $dimensions = $command->dimensions ?: 2; $typmod = $command->typmod ? 'true' : 'false'; $srid = $command->srid ?: 4326; + $schema = function_exists('config') ? config('postgis.schema') : 'public'; return sprintf( - "SELECT AddGeometryColumn('%s', '%s', %d, '%s', %d, %s)", - $blueprint->getTable(), - $command->column, - $srid, - strtoupper($command->type), - $dimensions, - $typmod + "SELECT %s.AddGeometryColumn('%s', '%s', %d, '%s.%s', %d, %s)", + $schema, + $blueprint->getTable(), + $command->column, + $srid, + $schema, + strtoupper($command->type), + $dimensions, + $typmod ); } @@ -211,7 +166,30 @@ protected function compileGeometry(Blueprint $blueprint, Fluent $command) * @param \Illuminate\Support\Fluent $column * @return boolean */ - protected function isValid($column) { + protected function isValid($column) + { return in_array(strtoupper($column->geomtype), PostgisGrammar::$allowed_geom_types) && is_int((int) $column->srid); } + + /** + * Create definition for geometry types. + * @param Fluent $column + * @param string $geometryType + * @return string + * @throws UnsupportedGeomtypeException + */ + private function createTypeDefinition(Fluent $column, $geometryType) + { + $schema = function_exists('config') ? config('postgis.schema') : 'public'; + $type = strtoupper($column->geomtype); + if ($this->isValid($column)) { + if ($type == 'GEOGRAPHY' && $column->srid != 4326) { + throw new UnsupportedGeomtypeException('Error with validation of srid! SRID of GEOGRAPHY must be 4326)'); + } + return $schema . '.' . $type . '(' . $geometryType . ', ' . $column->srid . ')'; + } else { + throw new UnsupportedGeomtypeException('Error with validation of geom type or srid!'); + } + } + } From 3836642da00b29d1ab9a583dd4129dbcd39cc5fb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miguel=20=C3=81ngel=20S=C3=A1nchez=20Palafox?= Date: Wed, 4 Sep 2019 10:31:11 -0500 Subject: [PATCH 19/83] Add Support for Laravel 6.0 --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index dda8fb4..f52f5ec 100644 --- a/composer.json +++ b/composer.json @@ -3,7 +3,7 @@ "description": "Postgis extensions for laravel. Aims to make it easy to work with geometries from laravel models", "require": { "php": ">=5.5", - "illuminate/database": "^5.2", + "illuminate/database": "^5.2|^6.0", "geo-io/wkb-parser": "^1.0", "jmikola/geojson": "^1.0", "bosnadev/database": "0.18.1" From 00662d2c315f9488303f9328e3cabb7b82d4936b Mon Sep 17 00:00:00 2001 From: Mirza Pasic Date: Wed, 11 Sep 2019 11:43:53 +0200 Subject: [PATCH 20/83] deps update --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index f52f5ec..d337adf 100644 --- a/composer.json +++ b/composer.json @@ -6,7 +6,7 @@ "illuminate/database": "^5.2|^6.0", "geo-io/wkb-parser": "^1.0", "jmikola/geojson": "^1.0", - "bosnadev/database": "0.18.1" + "bosnadev/database": "0.19.*" }, "require-dev": { "phpunit/phpunit": "~4.5", From 0f67c1ccc55c31e0192512f96af4d6627b002338 Mon Sep 17 00:00:00 2001 From: Aleh Zayats Date: Thu, 3 Oct 2019 18:58:45 +0300 Subject: [PATCH 21/83] add multipolygonz type --- src/Schema/Blueprint.php | 11 +++++++++++ src/Schema/Grammars/PostgisGrammar.php | 11 +++++++++++ 2 files changed, 22 insertions(+) diff --git a/src/Schema/Blueprint.php b/src/Schema/Blueprint.php index a321284..553180d 100644 --- a/src/Schema/Blueprint.php +++ b/src/Schema/Blueprint.php @@ -46,6 +46,17 @@ public function multipolygon($column, $geomtype = 'GEOGRAPHY', $srid = '4326') return $this->addColumn('multipolygon', $column, compact('geomtype', 'srid')); } + /** + * Add a multipolygonz column on the table + * + * @param $column + * @return \Illuminate\Support\Fluent + */ + public function multipolygonz($column, $geomtype = 'GEOGRAPHY', $srid = '4326') + { + return $this->addColumn('multipolygonz', $column, compact('geomtype', 'srid')); + } + /** * Add a linestring column on the table * diff --git a/src/Schema/Grammars/PostgisGrammar.php b/src/Schema/Grammars/PostgisGrammar.php index e3a0733..d982681 100644 --- a/src/Schema/Grammars/PostgisGrammar.php +++ b/src/Schema/Grammars/PostgisGrammar.php @@ -54,6 +54,17 @@ public function typeMultipolygon(Fluent $column) return $this->createTypeDefinition($column, 'MULTIPOLYGON'); } + /** + * Adds a statement to add a multipolygonz geometry column + * + * @param \Illuminate\Support\Fluent $column + * @return string + */ + public function typeMultiPolygonZ(Fluent $column) + { + return $this->createTypeDefinition($column, 'MULTIPOLYGONZ'); + } + /** * Adds a statement to add a linestring geometry column * From 935417a8ceefedcc3d7275f4bf4c87439d3cf6b3 Mon Sep 17 00:00:00 2001 From: Oleg Melnik Date: Tue, 3 Mar 2020 18:06:54 +0300 Subject: [PATCH 22/83] Update composer.json --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index d337adf..8473310 100644 --- a/composer.json +++ b/composer.json @@ -3,7 +3,7 @@ "description": "Postgis extensions for laravel. Aims to make it easy to work with geometries from laravel models", "require": { "php": ">=5.5", - "illuminate/database": "^5.2|^6.0", + "illuminate/database": "^5.2|^6.0|^7.0", "geo-io/wkb-parser": "^1.0", "jmikola/geojson": "^1.0", "bosnadev/database": "0.19.*" From 55ee06fbec66f3dd0ce0027a935174dd99baf25e Mon Sep 17 00:00:00 2001 From: Max Staack Date: Wed, 11 Mar 2020 13:19:49 +0100 Subject: [PATCH 23/83] cleanup --- composer.json | 86 ++++++++++--------- src/Connectors/ConnectionFactory.php | 4 +- src/DatabaseServiceProvider.php | 6 +- src/Eloquent/Builder.php | 4 +- src/Eloquent/PostgisTrait.php | 16 ++-- .../PostgisFieldsNotDefinedException.php | 2 +- .../PostgisTypesMalformedException.php | 2 +- src/Exceptions/UnknownWKTTypeException.php | 2 +- .../UnsupportedGeomtypeException.php | 2 +- src/Geometries/Factory.php | 2 +- src/Geometries/Geometry.php | 4 +- src/Geometries/GeometryCollection.php | 2 +- src/Geometries/GeometryInterface.php | 2 +- src/Geometries/LineString.php | 2 +- src/Geometries/MultiLineString.php | 2 +- src/Geometries/MultiPoint.php | 4 +- src/Geometries/MultiPolygon.php | 2 +- src/Geometries/Point.php | 2 +- src/Geometries/PointCollection.php | 2 +- src/Geometries/Polygon.php | 2 +- src/PostgisConnection.php | 2 +- src/Schema/Blueprint.php | 2 +- src/Schema/Builder.php | 2 +- src/Schema/Grammars/PostgisGrammar.php | 6 +- 24 files changed, 83 insertions(+), 79 deletions(-) diff --git a/composer.json b/composer.json index 8473310..d0ab8fa 100644 --- a/composer.json +++ b/composer.json @@ -1,46 +1,50 @@ { - "name": "phaza/laravel-postgis", - "description": "Postgis extensions for laravel. Aims to make it easy to work with geometries from laravel models", - "require": { - "php": ">=5.5", - "illuminate/database": "^5.2|^6.0|^7.0", - "geo-io/wkb-parser": "^1.0", - "jmikola/geojson": "^1.0", - "bosnadev/database": "0.19.*" - }, - "require-dev": { - "phpunit/phpunit": "~4.5", - "mockery/mockery": "0.9.*", - "codeclimate/php-test-reporter": "~0.3", - "illuminate/pagination": "~5.0" - }, - "autoload": { - "psr-4": { - "Phaza\\LaravelPostgis\\": "src/" - } + "name": "mstaack/laravel-postgis", + "description": "Postgis extensions for laravel. Aims to make it easy to work with geometries from laravel models", + "require": { + "php": ">=7.0", + "illuminate/database": "^6.0|^7.0", + "geo-io/wkb-parser": "^1.0", + "jmikola/geojson": "^1.0", + "bosnadev/database": "0.19.*" + }, + "require-dev": { + "phpunit/phpunit": "~4.5", + "mockery/mockery": "0.9.*", + "codeclimate/php-test-reporter": "~0.3", + "illuminate/pagination": "^6.0|^7.0" + }, + "autoload": { + "psr-4": { + "MStaack\\LaravelPostgis\\": "src/" + } + }, + "autoload-dev": { + "classmap": [ + "tests/BaseTestCase.php", + "tests/Stubs/" + ] + }, + "license": "MIT", + "authors": [ + { + "name": "Peter Haza", + "email": "peter.haza@gmail.com" }, - "autoload-dev": { - "classmap": [ - "tests/BaseTestCase.php", - "tests/Stubs/" - ] + { + "name": "Nicholas Barrett", + "email": "njbarrett7@gmail.com" }, - "license": "MIT", - "authors": [ - { - "name": "Peter Haza", - "email": "peter.haza@gmail.com" - }, - { - "name": "Nicholas Barrett", - "email": "njbarrett7@gmail.com" - } - ], - "extra": { - "laravel": { - "providers": [ - "Phaza\\LaravelPostgis\\DatabaseServiceProvider" - ] - } + { + "name": "Max Matteo Staack", + "email": "maxmatteostaack@gmail.com" + } + ], + "extra": { + "laravel": { + "providers": [ + "MStaack\\LaravelPostgis\\DatabaseServiceProvider" + ] } + } } diff --git a/src/Connectors/ConnectionFactory.php b/src/Connectors/ConnectionFactory.php index 715c2cc..99b9beb 100644 --- a/src/Connectors/ConnectionFactory.php +++ b/src/Connectors/ConnectionFactory.php @@ -1,7 +1,7 @@ -points) === 0) return false; return $this->points[0]->is3d(); } - + public function toWKT() { $wktType = 'MULTIPOINT'; diff --git a/src/Geometries/MultiPolygon.php b/src/Geometries/MultiPolygon.php index c97499c..80f7a9d 100644 --- a/src/Geometries/MultiPolygon.php +++ b/src/Geometries/MultiPolygon.php @@ -1,4 +1,4 @@ - Date: Wed, 11 Mar 2020 13:22:07 +0100 Subject: [PATCH 24/83] ci work --- .travis.yml | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/.travis.yml b/.travis.yml index 062e2ba..4a08aa4 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,14 +1,17 @@ language: php -dist: trusty +dist: bionic php: - - 5.5 - - 5.6 - 7.0 - 7.1 - 7.2 - 7.3 + - 7.4 - nightly +cache: + directories: + - vendor + matrix: allow_failures: - php: nightly From 9f2a49288d46e55aa0377b81e5c9d5eb0d4bff88 Mon Sep 17 00:00:00 2001 From: Max Staack Date: Wed, 11 Mar 2020 13:27:14 +0100 Subject: [PATCH 25/83] prepare github actions --- .github/run-tests.yml | 49 +++++++++++++++++++++++++++++++++++++++++++ .travis.yml | 30 -------------------------- 2 files changed, 49 insertions(+), 30 deletions(-) create mode 100644 .github/run-tests.yml delete mode 100644 .travis.yml diff --git a/.github/run-tests.yml b/.github/run-tests.yml new file mode 100644 index 0000000..4772bc9 --- /dev/null +++ b/.github/run-tests.yml @@ -0,0 +1,49 @@ +name: Test Suite + +on: [push] + +jobs: + test: + runs-on: ubuntu-latest + + strategy: + fail-fast: true + matrix: + php: [7.4, 7.3, 7.2, 7.1] + laravel: [7.*, 6.*] + dependency-version: [prefer-lowest, prefer-stable] + include: + - laravel: 7.* + testbench: 5.* + - laravel: 6.* + testbench: 4.* + + name: P${{ matrix.php }} - L${{ matrix.laravel }} - ${{ matrix.dependency-version }} + + steps: + - name: Checkout code + uses: actions/checkout@v2 + + - name: Cache dependencies + uses: actions/cache@v1 + with: + path: ~/.composer/cache/files + key: dependencies-laravel-${{ matrix.laravel }}-php-${{ matrix.php }}-composer-${{ hashFiles('composer.json') }} + keys: | + dependencies-laravel-${{ matrix.laravel }}-php-${{ matrix.php }}-composer- + dependencies-laravel-${{ matrix.laravel }}-php- + dependencies-laravel- + + - name: Setup PHP + uses: shivammathur/setup-php@v1 + with: + php-version: ${{ matrix.php }} + extensions: mbstring, dom, fileinfo, pgsql + + - name: Install dependencies + run: | + composer require "laravel/framework:${{ matrix.laravel }}" "orchestra/testbench:${{ matrix.testbench }}" --no-interaction --no-update + composer update --${{ matrix.dependency-version }} --prefer-dist --no-interaction --no-suggest + + - name: Execute tests + run: vendor/bin/phpunit diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index 4a08aa4..0000000 --- a/.travis.yml +++ /dev/null @@ -1,30 +0,0 @@ -language: php -dist: bionic -php: - - 7.0 - - 7.1 - - 7.2 - - 7.3 - - 7.4 - - nightly - -cache: - directories: - - vendor - -matrix: - allow_failures: - - php: nightly - -install: - - travis_retry composer install - -before_script: - - mkdir -p build/logs - -script: - - vendor/bin/phpunit --coverage-clover build/logs/clover.xml - -after_script: - - php vendor/bin/coveralls -v - - ./vendor/bin/test-reporter From 19810badb65788c214dbb15afa8bea846f6478cc Mon Sep 17 00:00:00 2001 From: Max Staack Date: Wed, 11 Mar 2020 13:40:15 +0100 Subject: [PATCH 26/83] fix folder --- .github/{ => workflows}/run-tests.yml | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename .github/{ => workflows}/run-tests.yml (100%) diff --git a/.github/run-tests.yml b/.github/workflows/run-tests.yml similarity index 100% rename from .github/run-tests.yml rename to .github/workflows/run-tests.yml From 4a4c5a8f3a1d34cd49dc31aa657d36ad6aec1ad3 Mon Sep 17 00:00:00 2001 From: Max Staack Date: Wed, 11 Mar 2020 14:01:24 +0100 Subject: [PATCH 27/83] fix ci --- .github/workflows/run-tests.yml | 70 ++++++++++++++++----------------- 1 file changed, 34 insertions(+), 36 deletions(-) diff --git a/.github/workflows/run-tests.yml b/.github/workflows/run-tests.yml index 4772bc9..8e2171c 100644 --- a/.github/workflows/run-tests.yml +++ b/.github/workflows/run-tests.yml @@ -1,49 +1,47 @@ name: Test Suite -on: [push] +on: [push, pull_request] jobs: - test: + tests: runs-on: ubuntu-latest strategy: - fail-fast: true - matrix: - php: [7.4, 7.3, 7.2, 7.1] - laravel: [7.*, 6.*] - dependency-version: [prefer-lowest, prefer-stable] - include: - - laravel: 7.* - testbench: 5.* - - laravel: 6.* - testbench: 4.* - - name: P${{ matrix.php }} - L${{ matrix.laravel }} - ${{ matrix.dependency-version }} + matrix: + php: [7.4, 7.3, 7.2] + database: [pgsql] + release: [stable, lowest] + include: + - php: 7.4 + release: stable + + services: + postgres: + image: kartoza/postgis:12.1 + env: + POSTGRES_USER: postgres + POSTGRES_PASSWORD: postgres + POSTGRES_DBNAME: postgres + ports: + - 5432/tcp + options: --health-cmd pg_isready --health-interval 10s --health-timeout 5s --health-retries 3 steps: - - name: Checkout code - uses: actions/checkout@v2 - - - name: Cache dependencies - uses: actions/cache@v1 + - uses: actions/checkout@v1 + - uses: actions/cache@v1 with: path: ~/.composer/cache/files - key: dependencies-laravel-${{ matrix.laravel }}-php-${{ matrix.php }}-composer-${{ hashFiles('composer.json') }} - keys: | - dependencies-laravel-${{ matrix.laravel }}-php-${{ matrix.php }}-composer- - dependencies-laravel-${{ matrix.laravel }}-php- - dependencies-laravel- - - - name: Setup PHP - uses: shivammathur/setup-php@v1 + key: php-${{ matrix.php }}-composer-${{ hashFiles('**/composer.json') }} + - uses: shivammathur/setup-php@v1 with: php-version: ${{ matrix.php }} - extensions: mbstring, dom, fileinfo, pgsql - - - name: Install dependencies - run: | - composer require "laravel/framework:${{ matrix.laravel }}" "orchestra/testbench:${{ matrix.testbench }}" --no-interaction --no-update - composer update --${{ matrix.dependency-version }} --prefer-dist --no-interaction --no-suggest - - - name: Execute tests - run: vendor/bin/phpunit + tools: pecl + extensions: bcmath, ctype, json, mbstring, openssl, pdo, pdo_${{ matrix.database }}, tokenizer, xml + coverage: ${{ matrix.coverage }} + - run: composer update --no-interaction --no-progress --no-suggest --prefer-dist --prefer-${{ matrix.release }} + - run: | + PHPUNIT_FLAGS=$([ "${{ matrix.coverage }}" == "xdebug" ] && echo "--coverage-clover=coverage.xml" || echo "") + vendor/bin/phpunit $PHPUNIT_FLAGS + env: + DATABASE: ${{ matrix.database }} + PGSQL_PORT: ${{ job.services.pgsql.ports[5432] }} From e715e59a8bd7b308efadb6014268832d06dab5c1 Mon Sep 17 00:00:00 2001 From: Max Staack Date: Wed, 11 Mar 2020 14:03:01 +0100 Subject: [PATCH 28/83] remove mapping --- .github/workflows/run-tests.yml | 3 --- 1 file changed, 3 deletions(-) diff --git a/.github/workflows/run-tests.yml b/.github/workflows/run-tests.yml index 8e2171c..f80f713 100644 --- a/.github/workflows/run-tests.yml +++ b/.github/workflows/run-tests.yml @@ -11,9 +11,6 @@ jobs: php: [7.4, 7.3, 7.2] database: [pgsql] release: [stable, lowest] - include: - - php: 7.4 - release: stable services: postgres: From f5df5d74a87d90c90b991adbe63c1938a49c2a59 Mon Sep 17 00:00:00 2001 From: Max Staack Date: Wed, 11 Mar 2020 14:04:10 +0100 Subject: [PATCH 29/83] cleanup --- .github/workflows/run-tests.yml | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/.github/workflows/run-tests.yml b/.github/workflows/run-tests.yml index f80f713..936b0da 100644 --- a/.github/workflows/run-tests.yml +++ b/.github/workflows/run-tests.yml @@ -9,7 +9,6 @@ jobs: strategy: matrix: php: [7.4, 7.3, 7.2] - database: [pgsql] release: [stable, lowest] services: @@ -33,12 +32,11 @@ jobs: with: php-version: ${{ matrix.php }} tools: pecl - extensions: bcmath, ctype, json, mbstring, openssl, pdo, pdo_${{ matrix.database }}, tokenizer, xml + extensions: mbstring, dom, fileinfo, pgsql, redis, intl coverage: ${{ matrix.coverage }} - run: composer update --no-interaction --no-progress --no-suggest --prefer-dist --prefer-${{ matrix.release }} - run: | - PHPUNIT_FLAGS=$([ "${{ matrix.coverage }}" == "xdebug" ] && echo "--coverage-clover=coverage.xml" || echo "") - vendor/bin/phpunit $PHPUNIT_FLAGS + vendor/bin/phpunit env: DATABASE: ${{ matrix.database }} PGSQL_PORT: ${{ job.services.pgsql.ports[5432] }} From 6f2d29bfa65f6483dfd08d0580153214288065f3 Mon Sep 17 00:00:00 2001 From: Max Staack Date: Wed, 11 Mar 2020 14:07:10 +0100 Subject: [PATCH 30/83] remove database refs --- .github/workflows/run-tests.yml | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/.github/workflows/run-tests.yml b/.github/workflows/run-tests.yml index 936b0da..c232c65 100644 --- a/.github/workflows/run-tests.yml +++ b/.github/workflows/run-tests.yml @@ -32,11 +32,8 @@ jobs: with: php-version: ${{ matrix.php }} tools: pecl - extensions: mbstring, dom, fileinfo, pgsql, redis, intl + extensions: mbstring, dom, fileinfo, pgsql, intl coverage: ${{ matrix.coverage }} - run: composer update --no-interaction --no-progress --no-suggest --prefer-dist --prefer-${{ matrix.release }} - run: | vendor/bin/phpunit - env: - DATABASE: ${{ matrix.database }} - PGSQL_PORT: ${{ job.services.pgsql.ports[5432] }} From 4109ad4b4f11b8937cac02bfea1eb3affa015bbe Mon Sep 17 00:00:00 2001 From: Max Staack Date: Wed, 11 Mar 2020 14:11:27 +0100 Subject: [PATCH 31/83] add badge --- README.md | 16 ++++----- tests/Connectors/ConnectionFactoryTest.php | 4 +-- tests/Eloquent/BuilderTest.php | 10 +++--- tests/Eloquent/PostgisTraitTest.php | 6 ++-- tests/Geometries/GeometryCollectionTest.php | 6 ++-- tests/Geometries/GeometryTest.php | 16 ++++----- tests/Geometries/LineStringTest.php | 4 +-- tests/Geometries/MultiLineStringTest.php | 6 ++-- tests/Geometries/MultiPointTest.php | 4 +-- tests/Geometries/MultiPolygonTest.php | 12 +++---- tests/Geometries/PointTest.php | 2 +- tests/Geometries/PolygonTest.php | 8 ++--- tests/Geometries/UnderLocaleTest.php | 36 ++++++++++---------- tests/PostgisConnectionTest.php | 4 +-- tests/Schema/BlueprintTest.php | 2 +- tests/Schema/BuilderTest.php | 6 ++-- tests/Schema/Grammars/PostgisGrammarTest.php | 10 +++--- 17 files changed, 76 insertions(+), 76 deletions(-) diff --git a/README.md b/README.md index fb08e5a..a76a2d3 100644 --- a/README.md +++ b/README.md @@ -1,9 +1,9 @@ Laravel postgis extension ========================= -[![Build Status](https://travis-ci.org/njbarrett/laravel-postgis.svg?branch=master)](https://travis-ci.org/njbarrett/laravel-postgis.svg?branch=master) -[![Code Climate](https://codeclimate.com/github/njbarrett/laravel-postgis/badges/gpa.svg)](https://codeclimate.com/github/njbarrett/laravel-postgis) -[![Coverage Status](https://coveralls.io/repos/github/njbarrett/laravel-postgis/badge.svg?branch=master)](https://coveralls.io/github/njbarrett/laravel-postgis?branch=master) +![Build Status](https://github.com/mstaack/laravel-postgis/workflows/.github/workflows/run-tests.yml/badge.svg) +[![Code Climate](https://codeclimate.com/github/mstaack/laravel-postgis/badges/gpa.svg)](https://codeclimate.com/github/mstaack/laravel-postgis) +[![Coverage Status](https://coveralls.io/repos/github/mstaack/laravel-postgis/badge.svg?branch=master)](https://coveralls.io/github/mstaack/laravel-postgis?branch=master) ## Features @@ -20,13 +20,13 @@ Laravel postgis extension ## Installation - composer require phaza/laravel-postgis + composer require mstaack/laravel-postgis For laravel >=5.5 that's all. This package supports Laravel new [Package Discovery](https://laravel.com/docs/5.5/packages#package-discovery). If you are using Laravel < 5.5, you also need to add the DatabaseServiceProvider to your `config/app.php` file. - 'Phaza\LaravelPostgis\DatabaseServiceProvider', + 'MStaack\LaravelPostgis\DatabaseServiceProvider', ## Usage @@ -53,7 +53,7 @@ Open the created migrations with your editor. ```PHP use Illuminate\Database\Migrations\Migration; -use Phaza\LaravelPostgis\Schema\Blueprint; +use MStaack\LaravelPostgis\Schema\Blueprint; class CreateLocationsTable extends Migration { @@ -115,8 +115,8 @@ what attributes/columns on your model are to be considered geometry objects. By ```PHP use Illuminate\Database\Eloquent\Model; -use Phaza\LaravelPostgis\Eloquent\PostgisTrait; -use Phaza\LaravelPostgis\Geometries\Point; +use MStaack\LaravelPostgis\Eloquent\PostgisTrait; +use MStaack\LaravelPostgis\Geometries\Point; class Location extends Model { diff --git a/tests/Connectors/ConnectionFactoryTest.php b/tests/Connectors/ConnectionFactoryTest.php index e394e6f..2cd96c6 100644 --- a/tests/Connectors/ConnectionFactoryTest.php +++ b/tests/Connectors/ConnectionFactoryTest.php @@ -1,8 +1,8 @@ assertInstanceOf(MultiPolygon::class, $polygon); $this->assertEquals(2, $polygon->count()); $this->assertEquals($wkt, $polygon->toWKT()); @@ -104,7 +104,7 @@ public function testFromWKT3d() { $wkt = 'MULTIPOLYGON Z(((1 1 1,2 1 3,2 2 2,1 2 0,1 1 1),(1 1 1,2 1 3,2 2 2,1 2 0,1 1)),((-1 -1 -1,-1 -2 -3,-2 -2 -2,-2 -1 0,-1 -1 -1)))'; $polygon = MultiPolygon::fromWKT($wkt); - + $this->assertInstanceOf(MultiPolygon::class, $polygon); $this->assertEquals(2, $polygon->count()); $this->assertEquals($wkt, $polygon->toWKT()); diff --git a/tests/Geometries/PointTest.php b/tests/Geometries/PointTest.php index 290cd38..20d0d10 100644 --- a/tests/Geometries/PointTest.php +++ b/tests/Geometries/PointTest.php @@ -1,6 +1,6 @@ polygon = new Polygon([$collection]); - + $collection = new LineString( [ new Point(1, 1, 1), diff --git a/tests/Geometries/UnderLocaleTest.php b/tests/Geometries/UnderLocaleTest.php index 8809241..0128149 100644 --- a/tests/Geometries/UnderLocaleTest.php +++ b/tests/Geometries/UnderLocaleTest.php @@ -1,46 +1,46 @@ markTestSkipped('The locale is not available for testing float output formatting'); } } - + public function testPointToWKT() { $point = new Point(1.5, 2.5); $this->assertEquals('POINT(2.5 1.5)', $point->toWKT()); } - + public function testMultiPointToWKT() { $multipoint = new MultiPoint([new Point(1.5, 1.5), new Point(1.5, 2.5), new Point(2.5, 2.5)]); $this->assertEquals('MULTIPOINT((1.5 1.5),(2.5 1.5),(2.5 2.5))', $multipoint->toWKT()); } - + public function testLineStringToWKT() { $linestring = new LineString([new Point(1.5, 1.5), new Point(2.5, 2.5), new Point(3.5, 3.5)]); @@ -64,7 +64,7 @@ public function testMultiLineStringToWKT() $this->assertSame('MULTILINESTRING((1.5 1.5,2.5 1.5,2.5 2.5,1.5 2.5,1.5 1.5))', $multilinestring->toWKT()); } - + public function testPolygonToWKT() { $collection = new LineString( @@ -78,10 +78,10 @@ public function testPolygonToWKT() ); $polygon = new Polygon([$collection]); - + $this->assertEquals('POLYGON((1.5 1.5,2.5 1.5,2.5 2.5,1.5 2.5,1.5 1.5))', $polygon->toWKT()); } - + public function testMultiPolygonToWKT() { $collection1 = new LineString( @@ -119,13 +119,13 @@ public function testMultiPolygonToWKT() $polygon2 = new Polygon([$collection3]); $multiPolygon = new MultiPolygon([$polygon1, $polygon2]); - + $this->assertEquals( 'MULTIPOLYGON(((1.5 1.5,2.5 1.5,2.5 2.5,1.5 2.5,1.5 1.5),(10.5 10.5,20.5 10.5,20.5 20.5,10.5 20.5,10.5 10.5)),((100.5 100.5,200.5 100.5,200.5 200.5,100.5 200.5,100.5 100.5)))', $multiPolygon->toWKT() ); } - + public function testGeometryCollectionToWKT() { $collection = new LineString( diff --git a/tests/PostgisConnectionTest.php b/tests/PostgisConnectionTest.php index caf336d..d088684 100644 --- a/tests/PostgisConnectionTest.php +++ b/tests/PostgisConnectionTest.php @@ -1,7 +1,7 @@ Date: Wed, 11 Mar 2020 14:25:20 +0100 Subject: [PATCH 32/83] wip --- composer.json | 12 ++-- phpunit.xml | 2 +- tests/BaseTestCase.php | 6 +- tests/Eloquent/BuilderTest.php | 2 +- tests/Eloquent/PostgisTraitTest.php | 16 ++--- tests/Geometries/GeometryCollectionTest.php | 2 +- tests/Geometries/LineStringTest.php | 2 +- tests/Geometries/MultiPolygonTest.php | 2 +- tests/Geometries/PolygonTest.php | 2 +- tests/Geometries/UnderLocaleTest.php | 16 ++--- tests/PostgisConnectionTest.php | 4 +- tests/Schema/BlueprintTest.php | 2 +- tests/Schema/Grammars/PostgisGrammarTest.php | 65 ++++++++++---------- 13 files changed, 68 insertions(+), 65 deletions(-) diff --git a/composer.json b/composer.json index d0ab8fa..76a5de9 100644 --- a/composer.json +++ b/composer.json @@ -2,17 +2,16 @@ "name": "mstaack/laravel-postgis", "description": "Postgis extensions for laravel. Aims to make it easy to work with geometries from laravel models", "require": { - "php": ">=7.0", + "php": ">=7.1", "illuminate/database": "^6.0|^7.0", "geo-io/wkb-parser": "^1.0", "jmikola/geojson": "^1.0", "bosnadev/database": "0.19.*" }, "require-dev": { - "phpunit/phpunit": "~4.5", - "mockery/mockery": "0.9.*", - "codeclimate/php-test-reporter": "~0.3", - "illuminate/pagination": "^6.0|^7.0" + "illuminate/pagination": "^6.0|^7.0", + "phpunit/phpunit": "^9.0", + "mockery/mockery": "^1.3" }, "autoload": { "psr-4": { @@ -46,5 +45,8 @@ "MStaack\\LaravelPostgis\\DatabaseServiceProvider" ] } + }, + "scripts": { + "test": "./vendor/bin/phpunit" } } diff --git a/phpunit.xml b/phpunit.xml index e3fcc31..76ba4f8 100644 --- a/phpunit.xml +++ b/phpunit.xml @@ -7,7 +7,7 @@ convertNoticesToExceptions="true" convertWarningsToExceptions="true" processIsolation="false" - stopOnFailure="false" + stopOnFailure="true" syntaxCheck="true" verbose="true"> diff --git a/tests/BaseTestCase.php b/tests/BaseTestCase.php index 48c9acc..bf91e13 100644 --- a/tests/BaseTestCase.php +++ b/tests/BaseTestCase.php @@ -1,8 +1,10 @@ queryBuilder = m::mock(QueryBuilder::class); $this->queryBuilder->makePartial(); diff --git a/tests/Eloquent/PostgisTraitTest.php b/tests/Eloquent/PostgisTraitTest.php index 739bebe..e73aac2 100644 --- a/tests/Eloquent/PostgisTraitTest.php +++ b/tests/Eloquent/PostgisTraitTest.php @@ -18,13 +18,13 @@ class PostgisTraitTest extends BaseTestCase */ protected $queries; - public function setUp() + public function setUp(): void { $this->model = new TestModel(); $this->queries = &$this->model->getConnection()->getPdo()->queries; } - public function tearDown() + public function tearDown(): void { $this->model->getConnection()->getPdo()->resetQueries(); } @@ -34,7 +34,7 @@ public function testInsertPointHasCorrectSql() $this->model->point = new Point(1, 2); $this->model->save(); - $this->assertContains("public.ST_GeogFromText('POINT(2 1)')", $this->queries[0]); + $this->assertStringContainsString("public.ST_GeogFromText('POINT(2 1)')", $this->queries[0]); } public function testInsertPointGeometryHasCorrectSql() @@ -42,7 +42,7 @@ public function testInsertPointGeometryHasCorrectSql() $this->model->point2 = new Point(1, 2); $this->model->save(); - $this->assertContains("public.ST_GeomFromText('POINT(2 1)', '27700')", $this->queries[0]); + $this->assertStringContainsString("public.ST_GeomFromText('POINT(2 1)', '27700')", $this->queries[0]); } public function testUpdatePointHasCorrectSql() @@ -51,7 +51,7 @@ public function testUpdatePointHasCorrectSql() $this->model->point = new Point(2, 4); $this->model->save(); - $this->assertContains("public.ST_GeogFromText('POINT(4 2)')", $this->queries[0]); + $this->assertStringContainsString("public.ST_GeogFromText('POINT(4 2)')", $this->queries[0]); } public function testInsertPoint3dHasCorrectSql() @@ -59,7 +59,7 @@ public function testInsertPoint3dHasCorrectSql() $this->model->point = new Point(1, 2, 3); $this->model->save(); - $this->assertContains("public.ST_GeogFromText('POINT Z(2 1 3)')", $this->queries[0]); + $this->assertStringContainsString("public.ST_GeogFromText('POINT Z(2 1 3)')", $this->queries[0]); } public function testInsertPoint3dGeometryHasCorrectSql() @@ -67,7 +67,7 @@ public function testInsertPoint3dGeometryHasCorrectSql() $this->model->point2 = new Point(1, 2, 3); $this->model->save(); - $this->assertContains("public.ST_GeomFromText('POINT Z(2 1 3)', '27700')", $this->queries[0]); + $this->assertStringContainsString("public.ST_GeomFromText('POINT Z(2 1 3)', '27700')", $this->queries[0]); } public function testUpdatePoint3dHasCorrectSql() @@ -76,7 +76,7 @@ public function testUpdatePoint3dHasCorrectSql() $this->model->point = new Point(2, 4, 6); $this->model->save(); - $this->assertContains("public.ST_GeogFromText('POINT Z(4 2 6)')", $this->queries[0]); + $this->assertStringContainsString("public.ST_GeogFromText('POINT Z(4 2 6)')", $this->queries[0]); } } diff --git a/tests/Geometries/GeometryCollectionTest.php b/tests/Geometries/GeometryCollectionTest.php index c250f51..6cc06ab 100644 --- a/tests/Geometries/GeometryCollectionTest.php +++ b/tests/Geometries/GeometryCollectionTest.php @@ -12,7 +12,7 @@ class GeometryCollectionTest extends BaseTestCase private $collection; private $collection3d; - protected function setUp() + protected function setUp(): void { $collection = new LineString( [ diff --git a/tests/Geometries/LineStringTest.php b/tests/Geometries/LineStringTest.php index 93be5dc..1339e23 100644 --- a/tests/Geometries/LineStringTest.php +++ b/tests/Geometries/LineStringTest.php @@ -8,7 +8,7 @@ class LineStringTest extends BaseTestCase private $points; private $points3d; - protected function setUp() + protected function setUp(): void { $this->points = [new Point(1, 1), new Point(2, 2), new Point(3, 3)]; $this->points3d = [new Point(1, 1, 1), new Point(2, 2, 2), new Point(3, 3, 3)]; diff --git a/tests/Geometries/MultiPolygonTest.php b/tests/Geometries/MultiPolygonTest.php index 6190fc6..9b09ac9 100644 --- a/tests/Geometries/MultiPolygonTest.php +++ b/tests/Geometries/MultiPolygonTest.php @@ -13,7 +13,7 @@ class MultiPolygonTest extends BaseTestCase private $multiPolygon; private $multiPolygon3d; - protected function setUp() + protected function setUp(): void { $collection1 = new LineString( [ diff --git a/tests/Geometries/PolygonTest.php b/tests/Geometries/PolygonTest.php index 59c2cd9..170390e 100644 --- a/tests/Geometries/PolygonTest.php +++ b/tests/Geometries/PolygonTest.php @@ -9,7 +9,7 @@ class PolygonTest extends BaseTestCase private $polygon; private $polygon3d; - protected function setUp() + protected function setUp(): void { $collection = new LineString( [ diff --git a/tests/Geometries/UnderLocaleTest.php b/tests/Geometries/UnderLocaleTest.php index 0128149..1afa323 100644 --- a/tests/Geometries/UnderLocaleTest.php +++ b/tests/Geometries/UnderLocaleTest.php @@ -1,29 +1,29 @@ markTestSkipped('The locale is not available for testing float output formatting'); } } diff --git a/tests/PostgisConnectionTest.php b/tests/PostgisConnectionTest.php index d088684..738d988 100644 --- a/tests/PostgisConnectionTest.php +++ b/tests/PostgisConnectionTest.php @@ -4,11 +4,11 @@ use MStaack\LaravelPostgis\Schema\Builder; use Stubs\PDOStub; -class PostgisConnectionTest extends PHPUnit_Framework_TestCase +class PostgisConnectionTest extends BaseTestCase { private $postgisConnection; - protected function setUp() + protected function setUp(): void { $pgConfig = ['driver' => 'pgsql', 'prefix' => 'prefix', 'database' => 'database', 'name' => 'foo']; $this->postgisConnection = new PostgisConnection(new PDOStub(), 'database', 'prefix', $pgConfig); diff --git a/tests/Schema/BlueprintTest.php b/tests/Schema/BlueprintTest.php index a47b141..ca9dd46 100644 --- a/tests/Schema/BlueprintTest.php +++ b/tests/Schema/BlueprintTest.php @@ -8,7 +8,7 @@ class BlueprintTest extends BaseTestCase { protected $blueprint; - public function setUp() + public function setUp(): void { parent::setUp(); diff --git a/tests/Schema/Grammars/PostgisGrammarTest.php b/tests/Schema/Grammars/PostgisGrammarTest.php index c96d868..6208914 100644 --- a/tests/Schema/Grammars/PostgisGrammarTest.php +++ b/tests/Schema/Grammars/PostgisGrammarTest.php @@ -4,7 +4,6 @@ use MStaack\LaravelPostgis\PostgisConnection; use MStaack\LaravelPostgis\Schema\Blueprint; use MStaack\LaravelPostgis\Schema\Grammars\PostgisGrammar; -use MStaack\LaravelPostgis\Exceptions\PostgisTypesMalformedException; use MStaack\LaravelPostgis\Exceptions\UnsupportedGeomtypeException; class PostgisGrammarBaseTest extends BaseTestCase @@ -15,8 +14,8 @@ public function testAddingPoint() $blueprint->point('foo'); $statements = $blueprint->toSql($this->getConnection(), $this->getGrammar()); - $this->assertEquals(1, count($statements)); - $this->assertContains('GEOGRAPHY(POINT, 4326)', $statements[0]); + $this->assertCount(1, $statements); + $this->assertStringContainsString('GEOGRAPHY(POINT, 4326)', $statements[0]); } public function testAddingPointGeom() @@ -24,13 +23,13 @@ public function testAddingPointGeom() $blueprint = new Blueprint('test'); $blueprint->point('foo', 'GEOMETRY', 27700); $statements = $blueprint->toSql($this->getConnection(), $this->getGrammar()); - $this->assertEquals(1, count($statements)); - $this->assertContains('GEOMETRY(POINT, 27700)', $statements[0]); + $this->assertCount(1, $statements); + $this->assertStringContainsString('GEOMETRY(POINT, 27700)', $statements[0]); } public function testAddingPointWrongSrid() { - $this->setExpectedException(UnsupportedGeomtypeException::class); + $this->expectException(UnsupportedGeomtypeException::class); $blueprint = new Blueprint('test'); $blueprint->point('foo', 'GEOGRAPHY', 27700); $statements = $blueprint->toSql($this->getConnection(), $this->getGrammar()); @@ -39,7 +38,7 @@ public function testAddingPointWrongSrid() public function testAddingPointUnsupported() { - $this->setExpectedException(UnsupportedGeomtypeException::class); + $this->expectException(UnsupportedGeomtypeException::class); $blueprint = new Blueprint('test'); $blueprint->point('foo', 'UNSUPPORTED_ENTRY', 27700); $statements = $blueprint->toSql($this->getConnection(), $this->getGrammar()); @@ -53,7 +52,7 @@ public function testAddingLinestring() $statements = $blueprint->toSql($this->getConnection(), $this->getGrammar()); $this->assertEquals(1, count($statements)); - $this->assertContains('GEOGRAPHY(LINESTRING, 4326)', $statements[0]); + $this->assertStringContainsString('GEOGRAPHY(LINESTRING, 4326)', $statements[0]); } public function testAddingLinestringGeom() @@ -62,12 +61,12 @@ public function testAddingLinestringGeom() $blueprint->linestring('foo', 'GEOMETRY', 27700); $statements = $blueprint->toSql($this->getConnection(), $this->getGrammar()); $this->assertEquals(1, count($statements)); - $this->assertContains('GEOMETRY(LINESTRING, 27700)', $statements[0]); + $this->assertStringContainsString('GEOMETRY(LINESTRING, 27700)', $statements[0]); } public function testAddingLinestringWrongSrid() { - $this->setExpectedException(UnsupportedGeomtypeException::class); + $this->expectException(UnsupportedGeomtypeException::class); $blueprint = new Blueprint('test'); $blueprint->linestring('foo', 'GEOGRAPHY', 27700); $statements = $blueprint->toSql($this->getConnection(), $this->getGrammar()); @@ -76,7 +75,7 @@ public function testAddingLinestringWrongSrid() public function testAddingLinestringUnsupported() { - $this->setExpectedException(UnsupportedGeomtypeException::class); + $this->expectException(UnsupportedGeomtypeException::class); $blueprint = new Blueprint('test'); $blueprint->linestring('foo', 'UNSUPPORTED_ENTRY', 27700); $statements = $blueprint->toSql($this->getConnection(), $this->getGrammar()); @@ -90,7 +89,7 @@ public function testAddingPolygon() $statements = $blueprint->toSql($this->getConnection(), $this->getGrammar()); $this->assertEquals(1, count($statements)); - $this->assertContains('GEOGRAPHY(POLYGON, 4326)', $statements[0]); + $this->assertStringContainsString('GEOGRAPHY(POLYGON, 4326)', $statements[0]); } public function testAddingPolygonGeom() @@ -99,12 +98,12 @@ public function testAddingPolygonGeom() $blueprint->polygon('foo', 'GEOMETRY', 27700); $statements = $blueprint->toSql($this->getConnection(), $this->getGrammar()); $this->assertEquals(1, count($statements)); - $this->assertContains('GEOMETRY(POLYGON, 27700)', $statements[0]); + $this->assertStringContainsString('GEOMETRY(POLYGON, 27700)', $statements[0]); } public function testAddingPolygonWrongSrid() { - $this->setExpectedException(UnsupportedGeomtypeException::class); + $this->expectException(UnsupportedGeomtypeException::class); $blueprint = new Blueprint('test'); $blueprint->polygon('foo', 'GEOGRAPHY', 27700); $statements = $blueprint->toSql($this->getConnection(), $this->getGrammar()); @@ -113,7 +112,7 @@ public function testAddingPolygonWrongSrid() public function testAddingPolygonUnsupported() { - $this->setExpectedException(UnsupportedGeomtypeException::class); + $this->expectException(UnsupportedGeomtypeException::class); $blueprint = new Blueprint('test'); $blueprint->polygon('foo', 'UNSUPPORTED_ENTRY', 27700); $statements = $blueprint->toSql($this->getConnection(), $this->getGrammar()); @@ -127,7 +126,7 @@ public function testAddingMultipoint() $statements = $blueprint->toSql($this->getConnection(), $this->getGrammar()); $this->assertEquals(1, count($statements)); - $this->assertContains('GEOGRAPHY(MULTIPOINT, 4326)', $statements[0]); + $this->assertStringContainsString('GEOGRAPHY(MULTIPOINT, 4326)', $statements[0]); } public function testAddingMultipointGeom() @@ -136,12 +135,12 @@ public function testAddingMultipointGeom() $blueprint->multipoint('foo', 'GEOMETRY', 27700); $statements = $blueprint->toSql($this->getConnection(), $this->getGrammar()); $this->assertEquals(1, count($statements)); - $this->assertContains('GEOMETRY(MULTIPOINT, 27700)', $statements[0]); + $this->assertStringContainsString('GEOMETRY(MULTIPOINT, 27700)', $statements[0]); } public function testAddingMultiPointWrongSrid() { - $this->setExpectedException(UnsupportedGeomtypeException::class); + $this->expectException(UnsupportedGeomtypeException::class); $blueprint = new Blueprint('test'); $blueprint->multipoint('foo', 'GEOGRAPHY', 27700); $statements = $blueprint->toSql($this->getConnection(), $this->getGrammar()); @@ -150,7 +149,7 @@ public function testAddingMultiPointWrongSrid() public function testAddingMultiPointUnsupported() { - $this->setExpectedException(UnsupportedGeomtypeException::class); + $this->expectException(UnsupportedGeomtypeException::class); $blueprint = new Blueprint('test'); $blueprint->multipoint('foo', 'UNSUPPORTED_ENTRY', 27700); $statements = $blueprint->toSql($this->getConnection(), $this->getGrammar()); @@ -164,7 +163,7 @@ public function testAddingMultiLinestring() $statements = $blueprint->toSql($this->getConnection(), $this->getGrammar()); $this->assertEquals(1, count($statements)); - $this->assertContains('GEOGRAPHY(MULTILINESTRING, 4326)', $statements[0]); + $this->assertStringContainsString('GEOGRAPHY(MULTILINESTRING, 4326)', $statements[0]); } public function testAddingMultiLinestringGeom() @@ -173,12 +172,12 @@ public function testAddingMultiLinestringGeom() $blueprint->multilinestring('foo', 'GEOMETRY', 27700); $statements = $blueprint->toSql($this->getConnection(), $this->getGrammar()); $this->assertEquals(1, count($statements)); - $this->assertContains('GEOMETRY(MULTILINESTRING, 27700)', $statements[0]); + $this->assertStringContainsString('GEOMETRY(MULTILINESTRING, 27700)', $statements[0]); } public function testAddingMultiLinestringWrongSrid() { - $this->setExpectedException(UnsupportedGeomtypeException::class); + $this->expectException(UnsupportedGeomtypeException::class); $blueprint = new Blueprint('test'); $blueprint->multilinestring('foo', 'GEOGRAPHY', 27700); $statements = $blueprint->toSql($this->getConnection(), $this->getGrammar()); @@ -187,7 +186,7 @@ public function testAddingMultiLinestringWrongSrid() public function testAddingMultiLinestringUnsupported() { - $this->setExpectedException(UnsupportedGeomtypeException::class); + $this->expectException(UnsupportedGeomtypeException::class); $blueprint = new Blueprint('test'); $blueprint->multilinestring('foo', 'UNSUPPORTED_ENTRY', 27700); $statements = $blueprint->toSql($this->getConnection(), $this->getGrammar()); @@ -201,7 +200,7 @@ public function testAddingMultiPolygon() $statements = $blueprint->toSql($this->getConnection(), $this->getGrammar()); $this->assertEquals(1, count($statements)); - $this->assertContains('GEOGRAPHY(MULTIPOLYGON, 4326)', $statements[0]); + $this->assertStringContainsString('GEOGRAPHY(MULTIPOLYGON, 4326)', $statements[0]); } public function testAddingMultiPolygonGeom() @@ -210,12 +209,12 @@ public function testAddingMultiPolygonGeom() $blueprint->multipolygon('foo', 'GEOMETRY', 27700); $statements = $blueprint->toSql($this->getConnection(), $this->getGrammar()); $this->assertEquals(1, count($statements)); - $this->assertContains('GEOMETRY(MULTIPOLYGON, 27700)', $statements[0]); + $this->assertStringContainsString('GEOMETRY(MULTIPOLYGON, 27700)', $statements[0]); } public function testAddingMultiPolygonWrongSrid() { - $this->setExpectedException(UnsupportedGeomtypeException::class); + $this->expectException(UnsupportedGeomtypeException::class); $blueprint = new Blueprint('test'); $blueprint->multipolygon('foo', 'GEOGRAPHY', 27700); $statements = $blueprint->toSql($this->getConnection(), $this->getGrammar()); @@ -224,7 +223,7 @@ public function testAddingMultiPolygonWrongSrid() public function testAddingMultiPolygonUnsupported() { - $this->setExpectedException(UnsupportedGeomtypeException::class); + $this->expectException(UnsupportedGeomtypeException::class); $blueprint = new Blueprint('test'); $blueprint->multipolygon('foo', 'UNSUPPORTED_ENTRY', 27700); $statements = $blueprint->toSql($this->getConnection(), $this->getGrammar()); @@ -238,7 +237,7 @@ public function testAddingGeography() $statements = $blueprint->toSql($this->getConnection(), $this->getGrammar()); $this->assertEquals(1, count($statements)); - $this->assertContains('GEOGRAPHY', $statements[0]); + $this->assertStringContainsString('GEOGRAPHY', $statements[0]); } public function testAddingGeometry() @@ -247,7 +246,7 @@ public function testAddingGeometry() $blueprint->geometry('foo'); $statements = $blueprint->toSql($this->getConnection(), $this->getGrammar()); $this->assertEquals(1, count($statements)); - $this->assertContains('GEOMETRY', $statements[0]); + $this->assertStringContainsString('GEOMETRY', $statements[0]); } public function testAddingGeometryCollection() @@ -257,8 +256,8 @@ public function testAddingGeometryCollection() $statements = $blueprint->toSql($this->getConnection(), $this->getGrammar()); $this->assertEquals(1, count($statements)); - $this->assertContains('AddGeometryColumn', $statements[0]); - $this->assertContains('GEOMETRYCOLLECTION', $statements[0]); + $this->assertStringContainsString('AddGeometryColumn', $statements[0]); + $this->assertStringContainsString('GEOMETRYCOLLECTION', $statements[0]); } public function testEnablePostgis() @@ -268,7 +267,7 @@ public function testEnablePostgis() $statements = $blueprint->toSql($this->getConnection(), $this->getGrammar()); $this->assertEquals(1, count($statements)); - $this->assertContains('CREATE EXTENSION postgis', $statements[0]); + $this->assertStringContainsString('CREATE EXTENSION postgis', $statements[0]); } public function testDisablePostgis() @@ -278,7 +277,7 @@ public function testDisablePostgis() $statements = $blueprint->toSql($this->getConnection(), $this->getGrammar()); $this->assertEquals(1, count($statements)); - $this->assertContains('DROP EXTENSION postgis', $statements[0]); + $this->assertStringContainsString('DROP EXTENSION postgis', $statements[0]); } /** From f77f9c9c328d661f0800980142a44605b1082cf6 Mon Sep 17 00:00:00 2001 From: Max Staack Date: Wed, 11 Mar 2020 14:29:33 +0100 Subject: [PATCH 33/83] more work --- tests/Eloquent/BuilderTest.php | 80 +++++++++++++++++----------------- 1 file changed, 40 insertions(+), 40 deletions(-) diff --git a/tests/Eloquent/BuilderTest.php b/tests/Eloquent/BuilderTest.php index c8d917f..5b7a8c9 100644 --- a/tests/Eloquent/BuilderTest.php +++ b/tests/Eloquent/BuilderTest.php @@ -26,17 +26,17 @@ protected function setUp(): void $this->queryBuilder->makePartial(); $this->queryBuilder - ->shouldReceive('from') - ->andReturn($this->queryBuilder); + ->shouldReceive('from') + ->andReturn($this->queryBuilder); $this->queryBuilder - ->shouldReceive('take') - ->with(1) - ->andReturn($this->queryBuilder); + ->shouldReceive('take') + ->with(1) + ->andReturn($this->queryBuilder); $this->queryBuilder - ->shouldReceive('get') - ->andReturn([]); + ->shouldReceive('get') + ->andReturn([]); $this->builder = new Builder($this->queryBuilder); $this->builder->setModel(new TestBuilderModel()); @@ -45,19 +45,19 @@ protected function setUp(): void public function testUpdate() { $this->queryBuilder - ->shouldReceive('raw') - ->with("public.ST_GeogFromText('POINT(2 1)')") - ->andReturn(new Expression("public.ST_GeogFromText('POINT(2 1)')")); + ->shouldReceive('raw') + ->with("public.ST_GeogFromText('POINT(2 1)')") + ->andReturn(new Expression("public.ST_GeogFromText('POINT(2 1)')")); $this->queryBuilder - ->shouldReceive('update') - ->andReturn(1); + ->shouldReceive('update') + ->andReturn(1); $builder = m::mock(Builder::class, [$this->queryBuilder])->makePartial(); $builder->shouldAllowMockingProtectedMethods(); $builder - ->shouldReceive('addUpdatedAtColumn') - ->andReturn(['point' => new Point(1, 2)]); + ->shouldReceive('addUpdatedAtColumn') + ->andReturn(['point' => new Point(1, 2)]); $builder->update(['point' => new Point(1, 2)]); } @@ -65,24 +65,24 @@ public function testUpdate() public function testUpdateLinestring() { $this->queryBuilder - ->shouldReceive('raw') - ->with("public.ST_GeogFromText('LINESTRING(0 0, 1 1, 2 2)')") - ->andReturn(new Expression("public.ST_GeogFromText('LINESTRING(0 0, 1 1, 2 2)')")); + ->shouldReceive('raw') + ->with("public.ST_GeogFromText('LINESTRING(0 0, 1 1, 2 2)')") + ->andReturn(new Expression("public.ST_GeogFromText('LINESTRING(0 0, 1 1, 2 2)')")); $this->queryBuilder - ->shouldReceive('update') - ->andReturn(1); + ->shouldReceive('update') + ->andReturn(1); $linestring = new LineString([new Point(0, 0), new Point(1, 1), new Point(2, 2)]); $builder = m::mock(Builder::class, [$this->queryBuilder])->makePartial(); $builder->shouldAllowMockingProtectedMethods(); $builder - ->shouldReceive('addUpdatedAtColumn') - ->andReturn(['linestring' => $linestring]); + ->shouldReceive('addUpdatedAtColumn') + ->andReturn(['linestring' => $linestring]); $builder - ->shouldReceive('asWKT')->with($linestring)->once(); + ->shouldReceive('asWKT')->with($linestring)->once(); $builder->update(['linestring' => $linestring]); } @@ -90,19 +90,19 @@ public function testUpdateLinestring() public function testUpdate3d() { $this->queryBuilder - ->shouldReceive('raw') - ->with("public.ST_GeogFromText('POINT Z(2 1 0)')") - ->andReturn(new Expression("public.ST_GeogFromText('POINT Z(2 1 0)')")); + ->shouldReceive('raw') + ->with("public.ST_GeogFromText('POINT Z(2 1 0)')") + ->andReturn(new Expression("public.ST_GeogFromText('POINT Z(2 1 0)')")); $this->queryBuilder - ->shouldReceive('update') - ->andReturn(1); + ->shouldReceive('update') + ->andReturn(1); $builder = m::mock(Builder::class, [$this->queryBuilder])->makePartial(); $builder->shouldAllowMockingProtectedMethods(); $builder - ->shouldReceive('addUpdatedAtColumn') - ->andReturn(['point' => new Point(1, 2, 0)]); + ->shouldReceive('addUpdatedAtColumn') + ->andReturn(['point' => new Point(1, 2, 0)]); $builder->update(['point' => new Point(1, 2, 0)]); } @@ -110,24 +110,24 @@ public function testUpdate3d() public function testUpdateLinestring3d() { $this->queryBuilder - ->shouldReceive('raw') - ->with("public.ST_GeogFromText('LINESTRING Z(0 0 0, 1 1 1, 2 2 2)')") - ->andReturn(new Expression("public.ST_GeogFromText('LINESTRING Z(0 0 0, 1 1 1, 2 2 2)')")); + ->shouldReceive('raw') + ->with("public.ST_GeogFromText('LINESTRING Z(0 0 0, 1 1 1, 2 2 2)')") + ->andReturn(new Expression("public.ST_GeogFromText('LINESTRING Z(0 0 0, 1 1 1, 2 2 2)')")); $this->queryBuilder - ->shouldReceive('update') - ->andReturn(1); + ->shouldReceive('update') + ->andReturn(1); $linestring = new LineString([new Point(0, 0, 0), new Point(1, 1, 1), new Point(2, 2, 2)]); $builder = m::mock(Builder::class, [$this->queryBuilder])->makePartial(); $builder->shouldAllowMockingProtectedMethods(); $builder - ->shouldReceive('addUpdatedAtColumn') - ->andReturn(['linestring' => $linestring]); + ->shouldReceive('addUpdatedAtColumn') + ->andReturn(['linestring' => $linestring]); $builder - ->shouldReceive('asWKT')->with($linestring)->once(); + ->shouldReceive('asWKT')->with($linestring)->once(); $builder->update(['linestring' => $linestring]); } @@ -138,8 +138,8 @@ class TestBuilderModel extends Model use PostgisTrait; protected $postgisFields = [ - 'point' => Point::class, - 'linestring' => LineString::class, - 'polygon' => Polygon::class + 'point' => Point::class, + 'linestring' => LineString::class, + 'polygon' => Polygon::class ]; } From f2a02af006855e1960ad182520df72406dbd97d0 Mon Sep 17 00:00:00 2001 From: Max Staack Date: Wed, 11 Mar 2020 14:31:28 +0100 Subject: [PATCH 34/83] use phpunit8 --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 76a5de9..45e6e2a 100644 --- a/composer.json +++ b/composer.json @@ -10,7 +10,7 @@ }, "require-dev": { "illuminate/pagination": "^6.0|^7.0", - "phpunit/phpunit": "^9.0", + "phpunit/phpunit": "^8.5", "mockery/mockery": "^1.3" }, "autoload": { From 6f3c9bc71db4aa152f9da43a85d438be28bcc8ce Mon Sep 17 00:00:00 2001 From: Mirza Pasic Date: Wed, 11 Mar 2020 14:32:52 +0100 Subject: [PATCH 35/83] Deps update --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index d0ab8fa..99896cb 100644 --- a/composer.json +++ b/composer.json @@ -6,7 +6,7 @@ "illuminate/database": "^6.0|^7.0", "geo-io/wkb-parser": "^1.0", "jmikola/geojson": "^1.0", - "bosnadev/database": "0.19.*" + "bosnadev/database": "0.20.*" }, "require-dev": { "phpunit/phpunit": "~4.5", From 228e2779fd19cb70251ecdf22574b7cdaeeb0c25 Mon Sep 17 00:00:00 2001 From: Max Staack Date: Wed, 11 Mar 2020 14:33:44 +0100 Subject: [PATCH 36/83] remove for now --- README.md | 2 -- 1 file changed, 2 deletions(-) diff --git a/README.md b/README.md index a76a2d3..4b4539c 100644 --- a/README.md +++ b/README.md @@ -2,8 +2,6 @@ Laravel postgis extension ========================= ![Build Status](https://github.com/mstaack/laravel-postgis/workflows/.github/workflows/run-tests.yml/badge.svg) -[![Code Climate](https://codeclimate.com/github/mstaack/laravel-postgis/badges/gpa.svg)](https://codeclimate.com/github/mstaack/laravel-postgis) -[![Coverage Status](https://coveralls.io/repos/github/mstaack/laravel-postgis/badge.svg?branch=master)](https://coveralls.io/github/mstaack/laravel-postgis?branch=master) ## Features From 4de6f51e4365d972aaa37c77bd41d62754687f65 Mon Sep 17 00:00:00 2001 From: Max Staack Date: Wed, 11 Mar 2020 14:44:23 +0100 Subject: [PATCH 37/83] fix badge url --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 4b4539c..d93f077 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,7 @@ Laravel postgis extension ========================= -![Build Status](https://github.com/mstaack/laravel-postgis/workflows/.github/workflows/run-tests.yml/badge.svg) +![Build Status](https://github.com/mstaack/laravel-postgis/workflows/Test%20Suite/badge.svg) ## Features From 8b8d11618a9249b064978f81cca6f1808ffc9188 Mon Sep 17 00:00:00 2001 From: Max Staack Date: Wed, 11 Mar 2020 14:52:43 +0100 Subject: [PATCH 38/83] update readme --- README.md | 14 ++++---------- 1 file changed, 4 insertions(+), 10 deletions(-) diff --git a/README.md b/README.md index d93f077..84b4bb3 100644 --- a/README.md +++ b/README.md @@ -8,13 +8,8 @@ Laravel postgis extension * Work with geometry classes instead of arrays. (`$myModel->myPoint = new Point(1,2)`) * Adds helpers in migrations. (`$table->polygon('myColumn')`) -### Future plans - - * Geometry functions on the geometry classes (contains(), equals(), distance(), etc… (HELP!)) - ## Versions -- Use 2.* for Laravel 5.1.* -- Use 3.* for Laravel > 5.2 +- Use 3.* for Laravel 5/6/7 ## Installation @@ -23,10 +18,9 @@ Laravel postgis extension For laravel >=5.5 that's all. This package supports Laravel new [Package Discovery](https://laravel.com/docs/5.5/packages#package-discovery). If you are using Laravel < 5.5, you also need to add the DatabaseServiceProvider to your `config/app.php` file. - - 'MStaack\LaravelPostgis\DatabaseServiceProvider', - - +```php +'MStaack\LaravelPostgis\DatabaseServiceProvider', +``` ## Usage First of all, make sure to enable postgis. From 4a7ee206557a8bbc16bab3a9125109e33a1f8bcc Mon Sep 17 00:00:00 2001 From: Max Staack Date: Wed, 11 Mar 2020 14:54:11 +0100 Subject: [PATCH 39/83] update --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 84b4bb3..808c2c1 100644 --- a/README.md +++ b/README.md @@ -9,7 +9,8 @@ Laravel postgis extension * Adds helpers in migrations. (`$table->polygon('myColumn')`) ## Versions -- Use 3.* for Laravel 5/6/7 +- Use 4.* for Laravel 5 +- Use 5.* for Laravel 6/7 ## Installation From bc5d73ee0e335bf621923ca2ed3efc9ac5c23797 Mon Sep 17 00:00:00 2001 From: Max Staack Date: Wed, 11 Mar 2020 14:57:30 +0100 Subject: [PATCH 40/83] update readme --- README.md | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 808c2c1..ab3e1fc 100644 --- a/README.md +++ b/README.md @@ -12,9 +12,18 @@ Laravel postgis extension - Use 4.* for Laravel 5 - Use 5.* for Laravel 6/7 +## Warning +This Package has been moved to a new owner and aims for Laravel 6/7 and PHP 7 support only soon! +Thanks to : +- https://github.com/njbarrett +- https://github.com/phaza +And all other contributers! + ## Installation - composer require mstaack/laravel-postgis +```bash +composer require mstaack/laravel-postgis +``` For laravel >=5.5 that's all. This package supports Laravel new [Package Discovery](https://laravel.com/docs/5.5/packages#package-discovery). From 922d21f4b059dcbb694c8a11c29949955ffd8dd8 Mon Sep 17 00:00:00 2001 From: Max Staack Date: Wed, 11 Mar 2020 14:58:13 +0100 Subject: [PATCH 41/83] cleanup --- README.md | 1 - 1 file changed, 1 deletion(-) diff --git a/README.md b/README.md index ab3e1fc..fef9b49 100644 --- a/README.md +++ b/README.md @@ -17,7 +17,6 @@ This Package has been moved to a new owner and aims for Laravel 6/7 and PHP 7 s Thanks to : - https://github.com/njbarrett - https://github.com/phaza -And all other contributers! ## Installation From abbbe1e2914b9b042371e9661f81492c83937b49 Mon Sep 17 00:00:00 2001 From: Max Staack Date: Wed, 11 Mar 2020 14:58:36 +0100 Subject: [PATCH 42/83] add contributors --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index fef9b49..61b9855 100644 --- a/README.md +++ b/README.md @@ -17,6 +17,7 @@ This Package has been moved to a new owner and aims for Laravel 6/7 and PHP 7 s Thanks to : - https://github.com/njbarrett - https://github.com/phaza +- https://github.com/bosnadev ## Installation From 9c417da041b18f21d2ace490df5d25b976d4bb75 Mon Sep 17 00:00:00 2001 From: Max Staack Date: Wed, 11 Mar 2020 15:00:20 +0100 Subject: [PATCH 43/83] rename --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 61b9855..3e0c497 100644 --- a/README.md +++ b/README.md @@ -17,7 +17,7 @@ This Package has been moved to a new owner and aims for Laravel 6/7 and PHP 7 s Thanks to : - https://github.com/njbarrett - https://github.com/phaza -- https://github.com/bosnadev +- https://github.com/mirzap ## Installation From 4e60b4a28e9acdecbd1bc3e295f622e6ad7ee654 Mon Sep 17 00:00:00 2001 From: Max Staack Date: Wed, 11 Mar 2020 15:14:39 +0100 Subject: [PATCH 44/83] cleanup and namespaces --- composer.json | 7 +- config/postgis.php | 6 +- src/Schema/Builder.php | 2 +- tests/BaseTestCase.php | 3 + tests/Connectors/ConnectionFactoryTest.php | 7 +- tests/Eloquent/BuilderTest.php | 26 ++- tests/Eloquent/PostgisTraitTest.php | 164 ------------------- tests/Geometries/GeometryCollectionTest.php | 3 + tests/Geometries/GeometryTest.php | 3 + tests/Geometries/LineStringTest.php | 3 + tests/Geometries/MultiLineStringTest.php | 5 +- tests/Geometries/MultiPointTest.php | 6 +- tests/Geometries/MultiPolygonTest.php | 11 +- tests/Geometries/PointTest.php | 3 + tests/Geometries/PolygonTest.php | 3 + tests/Geometries/UnderLocaleTest.php | 5 +- tests/PostgisConnectionTest.php | 4 +- tests/Schema/BlueprintTest.php | 6 +- tests/Schema/BuilderTest.php | 8 +- tests/Schema/Grammars/PostgisGrammarTest.php | 62 +++---- tests/Stubs/PDOStub.php | 3 +- 21 files changed, 108 insertions(+), 232 deletions(-) delete mode 100644 tests/Eloquent/PostgisTraitTest.php diff --git a/composer.json b/composer.json index 8ef84c1..3d38307 100644 --- a/composer.json +++ b/composer.json @@ -19,10 +19,9 @@ } }, "autoload-dev": { - "classmap": [ - "tests/BaseTestCase.php", - "tests/Stubs/" - ] + "psr-4": { + "MStaack\\LaravelPostgis\\Tests\\": "tests/" + } }, "license": "MIT", "authors": [ diff --git a/config/postgis.php b/config/postgis.php index 37ac3f5..696cd6c 100644 --- a/config/postgis.php +++ b/config/postgis.php @@ -1,7 +1,5 @@ 'public' // Schema for the Postgis extension - -]; \ No newline at end of file + 'schema' => 'public' // Schema for the Postgis extension +]; diff --git a/src/Schema/Builder.php b/src/Schema/Builder.php index 6d1276c..39d4b19 100644 --- a/src/Schema/Builder.php +++ b/src/Schema/Builder.php @@ -11,7 +11,7 @@ class Builder extends \Bosnadev\Database\Schema\Builder * @param Closure $callback * @return Blueprint */ - protected function createBlueprint($table, Closure $callback = null) + public function createBlueprint($table, Closure $callback = null) { return new Blueprint($table, $callback); } diff --git a/tests/BaseTestCase.php b/tests/BaseTestCase.php index bf91e13..7cd87ac 100644 --- a/tests/BaseTestCase.php +++ b/tests/BaseTestCase.php @@ -1,5 +1,8 @@ andReturn([]); $this->builder = new Builder($this->queryBuilder); - $this->builder->setModel(new TestBuilderModel()); + $this->builder->setModel(new class extends Model { + use PostgisTrait; + protected $postgisFields = [ + 'point' => Point::class, + 'linestring' => LineString::class, + 'polygon' => Polygon::class + ]; + }); } public function testUpdate() @@ -132,14 +141,3 @@ public function testUpdateLinestring3d() $builder->update(['linestring' => $linestring]); } } - -class TestBuilderModel extends Model -{ - use PostgisTrait; - - protected $postgisFields = [ - 'point' => Point::class, - 'linestring' => LineString::class, - 'polygon' => Polygon::class - ]; -} diff --git a/tests/Eloquent/PostgisTraitTest.php b/tests/Eloquent/PostgisTraitTest.php deleted file mode 100644 index e73aac2..0000000 --- a/tests/Eloquent/PostgisTraitTest.php +++ /dev/null @@ -1,164 +0,0 @@ -model = new TestModel(); - $this->queries = &$this->model->getConnection()->getPdo()->queries; - } - - public function tearDown(): void - { - $this->model->getConnection()->getPdo()->resetQueries(); - } - - public function testInsertPointHasCorrectSql() - { - $this->model->point = new Point(1, 2); - $this->model->save(); - - $this->assertStringContainsString("public.ST_GeogFromText('POINT(2 1)')", $this->queries[0]); - } - - public function testInsertPointGeometryHasCorrectSql() - { - $this->model->point2 = new Point(1, 2); - $this->model->save(); - - $this->assertStringContainsString("public.ST_GeomFromText('POINT(2 1)', '27700')", $this->queries[0]); - } - - public function testUpdatePointHasCorrectSql() - { - $this->model->exists = true; - $this->model->point = new Point(2, 4); - $this->model->save(); - - $this->assertStringContainsString("public.ST_GeogFromText('POINT(4 2)')", $this->queries[0]); - } - - public function testInsertPoint3dHasCorrectSql() - { - $this->model->point = new Point(1, 2, 3); - $this->model->save(); - - $this->assertStringContainsString("public.ST_GeogFromText('POINT Z(2 1 3)')", $this->queries[0]); - } - - public function testInsertPoint3dGeometryHasCorrectSql() - { - $this->model->point2 = new Point(1, 2, 3); - $this->model->save(); - - $this->assertStringContainsString("public.ST_GeomFromText('POINT Z(2 1 3)', '27700')", $this->queries[0]); - } - - public function testUpdatePoint3dHasCorrectSql() - { - $this->model->exists = true; - $this->model->point = new Point(2, 4, 6); - $this->model->save(); - - $this->assertStringContainsString("public.ST_GeogFromText('POINT Z(4 2 6)')", $this->queries[0]); - } -} - -class TestModel extends Model -{ - use PostgisTrait; - - protected $postgisFields = [ - 'point' => Point::class, - 'point2' => Polygon::class, - ]; - - protected $postgisTypes = [ - 'point2' => [ - 'geomtype' => 'geometry', - 'srid' => 27700 - ] - ]; - - - public static $pdo; - - public static function resolveConnection($connection = null) - { - if (is_null(static::$pdo)) { - static::$pdo = m::mock('TestPDO')->makePartial(); - } - - return new PostgisConnection(static::$pdo); - } - - public function testrelatedmodels() - { - return $this->hasMany(TestRelatedModel::class); - } - - public function testrelatedmodels2() - { - return $this->belongsToMany(TestRelatedModel::class); - } - -} - -class TestRelatedModel extends TestModel -{ - public function testmodel() - { - return $this->belongsTo(TestModel::class); - } - - public function testmodels() - { - return $this->belongsToMany(TestModel::class); - } -} - -class TestPDO extends PDO -{ - public $queries = []; - public $counter = 1; - - public function prepare($statement, $driver_options = null) - { - $this->queries[] = $statement; - - $stmt = m::mock('PDOStatement'); - $stmt->shouldReceive('setFetchMode'); - $stmt->shouldReceive('bindValue')->zeroOrMoreTimes(); - $stmt->shouldReceive('execute'); - $stmt->shouldReceive('fetchAll')->andReturn([['id' => 1, 'point' => 'POINT(1 2)']]); - $stmt->shouldReceive('rowCount')->andReturn(1); - - return $stmt; - } - - public function lastInsertId($name = null) - { - return $this->counter++; - } - - public function resetQueries() - { - $this->queries = []; - } -} diff --git a/tests/Geometries/GeometryCollectionTest.php b/tests/Geometries/GeometryCollectionTest.php index 6cc06ab..7bf86e4 100644 --- a/tests/Geometries/GeometryCollectionTest.php +++ b/tests/Geometries/GeometryCollectionTest.php @@ -1,8 +1,11 @@ assertEquals(3, $multipoint->count()); } + public function testFromWKT3d() { $multipoint = MultiPoint::fromWKT('MULTIPOINT Z((1 1 1),(2 1 3),(2 2 2))'); diff --git a/tests/Geometries/MultiPolygonTest.php b/tests/Geometries/MultiPolygonTest.php index 9b09ac9..6f82117 100644 --- a/tests/Geometries/MultiPolygonTest.php +++ b/tests/Geometries/MultiPolygonTest.php @@ -1,9 +1,12 @@ assertInstanceOf(Polygon::class, $polygon->getPolygons()[0]); @@ -138,7 +141,7 @@ public function testGetPolygons() public function testGetPolygons3d() { $polygon = MultiPolygon::fromWKT( - 'MULTIPOLYGON Z(((0 0 0,4 0 0,4 4 4,0 4 0,0 0 0),(1 1 1,2 1 3,2 2 2,1 2 0,1 1 1)), ((-1 -1 -1,-1 -2 0,-2 -2 -2,-2 -1 -3,-1 -1 -1)))' + 'MULTIPOLYGON Z(((0 0 0,4 0 0,4 4 4,0 4 0,0 0 0),(1 1 1,2 1 3,2 2 2,1 2 0,1 1 1)), ((-1 -1 -1,-1 -2 0,-2 -2 -2,-2 -1 -3,-1 -1 -1)))' ); $this->assertInstanceOf(Polygon::class, $polygon->getPolygons()[0]); @@ -147,7 +150,7 @@ public function testGetPolygons3d() public function testIssue12() { $polygon = MultiPolygon::fromWKT( - 'MULTIPOLYGON(((-80.214554 25.769598 0 0,-80.2147 25.774514 0 0,-80.212983 25.77456 0 0,-80.212977 25.773597 0 0,-80.211448 25.773655 0 0,-80.211498 25.774579 0 0,-80.209432 25.774665 0 0,-80.209392 25.773667 0 0,-80.204387 25.773834 0 0,-80.199383 25.774324 0 0,-80.197718 25.774031 0 0,-80.197757 25.774975 0 0,-80.193655 25.775108 0 0,-80.193623 25.774134 0 0,-80.191855 25.772551 0 0,-80.193442 25.76969 0 0,-80.192231 25.768345 0 0,-80.192879 25.758009 0 0,-80.196301 25.759985 0 0,-80.195608 25.76152 0 0,-80.198856 25.761454 0 0,-80.200646 25.763287 0 0,-80.20401 25.763164 0 0,-80.204023 25.76367 0 0,-80.205673 25.763141 0 0,-80.214326 25.762935 0 0,-80.214451 25.765883 0 0,-80.214539 25.768649 0 0,-80.216203 25.76858 0 0,-80.214554 25.769598 0 0)))' + 'MULTIPOLYGON(((-80.214554 25.769598 0 0,-80.2147 25.774514 0 0,-80.212983 25.77456 0 0,-80.212977 25.773597 0 0,-80.211448 25.773655 0 0,-80.211498 25.774579 0 0,-80.209432 25.774665 0 0,-80.209392 25.773667 0 0,-80.204387 25.773834 0 0,-80.199383 25.774324 0 0,-80.197718 25.774031 0 0,-80.197757 25.774975 0 0,-80.193655 25.775108 0 0,-80.193623 25.774134 0 0,-80.191855 25.772551 0 0,-80.193442 25.76969 0 0,-80.192231 25.768345 0 0,-80.192879 25.758009 0 0,-80.196301 25.759985 0 0,-80.195608 25.76152 0 0,-80.198856 25.761454 0 0,-80.200646 25.763287 0 0,-80.20401 25.763164 0 0,-80.204023 25.76367 0 0,-80.205673 25.763141 0 0,-80.214326 25.762935 0 0,-80.214451 25.765883 0 0,-80.214539 25.768649 0 0,-80.216203 25.76858 0 0,-80.214554 25.769598 0 0)))' ); $this->assertInstanceOf(MultiPolygon::class, $polygon); @@ -156,7 +159,7 @@ public function testIssue12() public function testIssue123d() { $polygon = MultiPolygon::fromWKT( - 'MULTIPOLYGON Z(((-80.214554 25.769598 0 0,-80.2147 25.774514 0 0,-80.212983 25.77456 0 0,-80.212977 25.773597 0 0,-80.211448 25.773655 0 0,-80.211498 25.774579 0 0,-80.209432 25.774665 0 0,-80.209392 25.773667 0 0,-80.204387 25.773834 0 0,-80.199383 25.774324 0 0,-80.197718 25.774031 0 0,-80.197757 25.774975 0 0,-80.193655 25.775108 0 0,-80.193623 25.774134 0 0,-80.191855 25.772551 0 0,-80.193442 25.76969 0 0,-80.192231 25.768345 0 0,-80.192879 25.758009 0 0,-80.196301 25.759985 0 0,-80.195608 25.76152 0 0,-80.198856 25.761454 0 0,-80.200646 25.763287 0 0,-80.20401 25.763164 0 0,-80.204023 25.76367 0 0,-80.205673 25.763141 0 0,-80.214326 25.762935 0 0,-80.214451 25.765883 0 0,-80.214539 25.768649 0 0,-80.216203 25.76858 0 0,-80.214554 25.769598 0 0)))' + 'MULTIPOLYGON Z(((-80.214554 25.769598 0 0,-80.2147 25.774514 0 0,-80.212983 25.77456 0 0,-80.212977 25.773597 0 0,-80.211448 25.773655 0 0,-80.211498 25.774579 0 0,-80.209432 25.774665 0 0,-80.209392 25.773667 0 0,-80.204387 25.773834 0 0,-80.199383 25.774324 0 0,-80.197718 25.774031 0 0,-80.197757 25.774975 0 0,-80.193655 25.775108 0 0,-80.193623 25.774134 0 0,-80.191855 25.772551 0 0,-80.193442 25.76969 0 0,-80.192231 25.768345 0 0,-80.192879 25.758009 0 0,-80.196301 25.759985 0 0,-80.195608 25.76152 0 0,-80.198856 25.761454 0 0,-80.200646 25.763287 0 0,-80.20401 25.763164 0 0,-80.204023 25.76367 0 0,-80.205673 25.763141 0 0,-80.214326 25.762935 0 0,-80.214451 25.765883 0 0,-80.214539 25.768649 0 0,-80.216203 25.76858 0 0,-80.214554 25.769598 0 0)))' ); $this->assertInstanceOf(MultiPolygon::class, $polygon); diff --git a/tests/Geometries/PointTest.php b/tests/Geometries/PointTest.php index 20d0d10..97ecaee 100644 --- a/tests/Geometries/PointTest.php +++ b/tests/Geometries/PointTest.php @@ -1,6 +1,9 @@ markTestSkipped('The locale is not available for testing float output formatting'); } } diff --git a/tests/PostgisConnectionTest.php b/tests/PostgisConnectionTest.php index 738d988..a9af3c2 100644 --- a/tests/PostgisConnectionTest.php +++ b/tests/PostgisConnectionTest.php @@ -1,8 +1,10 @@ point('foo', 'GEOGRAPHY', 27700); $statements = $blueprint->toSql($this->getConnection(), $this->getGrammar()); - $this->assertEquals(1, count($statements)); + $this->assertCount(1, $statements);; } public function testAddingPointUnsupported() @@ -42,7 +46,7 @@ public function testAddingPointUnsupported() $blueprint = new Blueprint('test'); $blueprint->point('foo', 'UNSUPPORTED_ENTRY', 27700); $statements = $blueprint->toSql($this->getConnection(), $this->getGrammar()); - $this->assertEquals(1, count($statements)); + $this->assertCount(1, $statements);; } public function testAddingLinestring() @@ -51,7 +55,7 @@ public function testAddingLinestring() $blueprint->linestring('foo'); $statements = $blueprint->toSql($this->getConnection(), $this->getGrammar()); - $this->assertEquals(1, count($statements)); + $this->assertCount(1, $statements);; $this->assertStringContainsString('GEOGRAPHY(LINESTRING, 4326)', $statements[0]); } @@ -60,7 +64,7 @@ public function testAddingLinestringGeom() $blueprint = new Blueprint('test'); $blueprint->linestring('foo', 'GEOMETRY', 27700); $statements = $blueprint->toSql($this->getConnection(), $this->getGrammar()); - $this->assertEquals(1, count($statements)); + $this->assertCount(1, $statements);; $this->assertStringContainsString('GEOMETRY(LINESTRING, 27700)', $statements[0]); } @@ -70,7 +74,7 @@ public function testAddingLinestringWrongSrid() $blueprint = new Blueprint('test'); $blueprint->linestring('foo', 'GEOGRAPHY', 27700); $statements = $blueprint->toSql($this->getConnection(), $this->getGrammar()); - $this->assertEquals(1, count($statements)); + $this->assertCount(1, $statements);; } public function testAddingLinestringUnsupported() @@ -79,7 +83,7 @@ public function testAddingLinestringUnsupported() $blueprint = new Blueprint('test'); $blueprint->linestring('foo', 'UNSUPPORTED_ENTRY', 27700); $statements = $blueprint->toSql($this->getConnection(), $this->getGrammar()); - $this->assertEquals(1, count($statements)); + $this->assertCount(1, $statements); } public function testAddingPolygon() @@ -88,7 +92,7 @@ public function testAddingPolygon() $blueprint->polygon('foo'); $statements = $blueprint->toSql($this->getConnection(), $this->getGrammar()); - $this->assertEquals(1, count($statements)); + $this->assertCount(1, $statements); $this->assertStringContainsString('GEOGRAPHY(POLYGON, 4326)', $statements[0]); } @@ -97,7 +101,7 @@ public function testAddingPolygonGeom() $blueprint = new Blueprint('test'); $blueprint->polygon('foo', 'GEOMETRY', 27700); $statements = $blueprint->toSql($this->getConnection(), $this->getGrammar()); - $this->assertEquals(1, count($statements)); + $this->assertCount(1, $statements); $this->assertStringContainsString('GEOMETRY(POLYGON, 27700)', $statements[0]); } @@ -107,7 +111,7 @@ public function testAddingPolygonWrongSrid() $blueprint = new Blueprint('test'); $blueprint->polygon('foo', 'GEOGRAPHY', 27700); $statements = $blueprint->toSql($this->getConnection(), $this->getGrammar()); - $this->assertEquals(1, count($statements)); + $this->assertCount(1, $statements); } public function testAddingPolygonUnsupported() @@ -116,7 +120,7 @@ public function testAddingPolygonUnsupported() $blueprint = new Blueprint('test'); $blueprint->polygon('foo', 'UNSUPPORTED_ENTRY', 27700); $statements = $blueprint->toSql($this->getConnection(), $this->getGrammar()); - $this->assertEquals(1, count($statements)); + $this->assertCount(1, $statements); } public function testAddingMultipoint() @@ -125,7 +129,7 @@ public function testAddingMultipoint() $blueprint->multipoint('foo'); $statements = $blueprint->toSql($this->getConnection(), $this->getGrammar()); - $this->assertEquals(1, count($statements)); + $this->assertCount(1, $statements); $this->assertStringContainsString('GEOGRAPHY(MULTIPOINT, 4326)', $statements[0]); } @@ -134,7 +138,7 @@ public function testAddingMultipointGeom() $blueprint = new Blueprint('test'); $blueprint->multipoint('foo', 'GEOMETRY', 27700); $statements = $blueprint->toSql($this->getConnection(), $this->getGrammar()); - $this->assertEquals(1, count($statements)); + $this->assertCount(1, $statements); $this->assertStringContainsString('GEOMETRY(MULTIPOINT, 27700)', $statements[0]); } @@ -144,7 +148,7 @@ public function testAddingMultiPointWrongSrid() $blueprint = new Blueprint('test'); $blueprint->multipoint('foo', 'GEOGRAPHY', 27700); $statements = $blueprint->toSql($this->getConnection(), $this->getGrammar()); - $this->assertEquals(1, count($statements)); + $this->assertCount(1, $statements); } public function testAddingMultiPointUnsupported() @@ -153,7 +157,7 @@ public function testAddingMultiPointUnsupported() $blueprint = new Blueprint('test'); $blueprint->multipoint('foo', 'UNSUPPORTED_ENTRY', 27700); $statements = $blueprint->toSql($this->getConnection(), $this->getGrammar()); - $this->assertEquals(1, count($statements)); + $this->assertCount(1, $statements);; } public function testAddingMultiLinestring() @@ -162,7 +166,7 @@ public function testAddingMultiLinestring() $blueprint->multilinestring('foo'); $statements = $blueprint->toSql($this->getConnection(), $this->getGrammar()); - $this->assertEquals(1, count($statements)); + $this->assertCount(1, $statements);; $this->assertStringContainsString('GEOGRAPHY(MULTILINESTRING, 4326)', $statements[0]); } @@ -171,7 +175,7 @@ public function testAddingMultiLinestringGeom() $blueprint = new Blueprint('test'); $blueprint->multilinestring('foo', 'GEOMETRY', 27700); $statements = $blueprint->toSql($this->getConnection(), $this->getGrammar()); - $this->assertEquals(1, count($statements)); + $this->assertCount(1, $statements);; $this->assertStringContainsString('GEOMETRY(MULTILINESTRING, 27700)', $statements[0]); } @@ -181,7 +185,7 @@ public function testAddingMultiLinestringWrongSrid() $blueprint = new Blueprint('test'); $blueprint->multilinestring('foo', 'GEOGRAPHY', 27700); $statements = $blueprint->toSql($this->getConnection(), $this->getGrammar()); - $this->assertEquals(1, count($statements)); + $this->assertCount(1, $statements);; } public function testAddingMultiLinestringUnsupported() @@ -190,7 +194,7 @@ public function testAddingMultiLinestringUnsupported() $blueprint = new Blueprint('test'); $blueprint->multilinestring('foo', 'UNSUPPORTED_ENTRY', 27700); $statements = $blueprint->toSql($this->getConnection(), $this->getGrammar()); - $this->assertEquals(1, count($statements)); + $this->assertCount(1, $statements);; } public function testAddingMultiPolygon() @@ -199,7 +203,7 @@ public function testAddingMultiPolygon() $blueprint->multipolygon('foo'); $statements = $blueprint->toSql($this->getConnection(), $this->getGrammar()); - $this->assertEquals(1, count($statements)); + $this->assertCount(1, $statements);; $this->assertStringContainsString('GEOGRAPHY(MULTIPOLYGON, 4326)', $statements[0]); } @@ -208,7 +212,7 @@ public function testAddingMultiPolygonGeom() $blueprint = new Blueprint('test'); $blueprint->multipolygon('foo', 'GEOMETRY', 27700); $statements = $blueprint->toSql($this->getConnection(), $this->getGrammar()); - $this->assertEquals(1, count($statements)); + $this->assertCount(1, $statements);; $this->assertStringContainsString('GEOMETRY(MULTIPOLYGON, 27700)', $statements[0]); } @@ -218,7 +222,7 @@ public function testAddingMultiPolygonWrongSrid() $blueprint = new Blueprint('test'); $blueprint->multipolygon('foo', 'GEOGRAPHY', 27700); $statements = $blueprint->toSql($this->getConnection(), $this->getGrammar()); - $this->assertEquals(1, count($statements)); + $this->assertCount(1, $statements);; } public function testAddingMultiPolygonUnsupported() @@ -227,7 +231,7 @@ public function testAddingMultiPolygonUnsupported() $blueprint = new Blueprint('test'); $blueprint->multipolygon('foo', 'UNSUPPORTED_ENTRY', 27700); $statements = $blueprint->toSql($this->getConnection(), $this->getGrammar()); - $this->assertEquals(1, count($statements)); + $this->assertCount(1, $statements);; } public function testAddingGeography() @@ -236,7 +240,7 @@ public function testAddingGeography() $blueprint->geography('foo'); $statements = $blueprint->toSql($this->getConnection(), $this->getGrammar()); - $this->assertEquals(1, count($statements)); + $this->assertCount(1, $statements);; $this->assertStringContainsString('GEOGRAPHY', $statements[0]); } @@ -245,7 +249,7 @@ public function testAddingGeometry() $blueprint = new Blueprint('test'); $blueprint->geometry('foo'); $statements = $blueprint->toSql($this->getConnection(), $this->getGrammar()); - $this->assertEquals(1, count($statements)); + $this->assertCount(1, $statements);; $this->assertStringContainsString('GEOMETRY', $statements[0]); } @@ -255,7 +259,7 @@ public function testAddingGeometryCollection() $blueprint->geometrycollection('foo'); $statements = $blueprint->toSql($this->getConnection(), $this->getGrammar()); - $this->assertEquals(1, count($statements)); + $this->assertCount(1, $statements);; $this->assertStringContainsString('AddGeometryColumn', $statements[0]); $this->assertStringContainsString('GEOMETRYCOLLECTION', $statements[0]); } @@ -266,7 +270,7 @@ public function testEnablePostgis() $blueprint->enablePostgis(); $statements = $blueprint->toSql($this->getConnection(), $this->getGrammar()); - $this->assertEquals(1, count($statements)); + $this->assertCount(1, $statements);; $this->assertStringContainsString('CREATE EXTENSION postgis', $statements[0]); } @@ -276,7 +280,7 @@ public function testDisablePostgis() $blueprint->disablePostgis(); $statements = $blueprint->toSql($this->getConnection(), $this->getGrammar()); - $this->assertEquals(1, count($statements)); + $this->assertCount(1, $statements);; $this->assertStringContainsString('DROP EXTENSION postgis', $statements[0]); } diff --git a/tests/Stubs/PDOStub.php b/tests/Stubs/PDOStub.php index 23d8b6e..89034d1 100644 --- a/tests/Stubs/PDOStub.php +++ b/tests/Stubs/PDOStub.php @@ -1,5 +1,6 @@ Date: Wed, 11 Mar 2020 15:21:31 +0100 Subject: [PATCH 45/83] cleanup namespaces --- README.md | 13 +++++++-- src/DatabaseServiceProvider.php | 21 +++++++------- src/Geometries/Factory.php | 40 ++++++++++++++------------- src/Geometries/Geometry.php | 4 ++- src/Geometries/GeometryCollection.php | 5 ++-- src/Geometries/GeometryInterface.php | 4 ++- src/Geometries/LineString.php | 8 ++++-- src/Geometries/MultiLineString.php | 8 ++++-- src/Geometries/MultiPoint.php | 8 ++++-- src/Geometries/MultiPolygon.php | 16 ++++++----- src/Geometries/Point.php | 12 ++++---- src/Geometries/PointCollection.php | 4 ++- src/Geometries/Polygon.php | 14 ++++++---- src/PostgisConnection.php | 13 ++++++--- 14 files changed, 101 insertions(+), 69 deletions(-) diff --git a/README.md b/README.md index 3e0c497..193da53 100644 --- a/README.md +++ b/README.md @@ -5,8 +5,15 @@ Laravel postgis extension ## Features - * Work with geometry classes instead of arrays. (`$myModel->myPoint = new Point(1,2)`) - * Adds helpers in migrations. (`$table->polygon('myColumn')`) + * Work with geometry classes instead of arrays. +```php +$model->myPoint = new Point(1,2); //lat, long +``` + +* Adds helpers in migrations. +```php +$table->polygon('myColumn'); +``` ## Versions - Use 4.* for Laravel 5 @@ -19,6 +26,8 @@ Thanks to : - https://github.com/phaza - https://github.com/mirzap +Fluent in Laravel Packages and Postgres/Postgis? Consider contributing! We are looking for anyone that wants to help out! + ## Installation ```bash diff --git a/src/DatabaseServiceProvider.php b/src/DatabaseServiceProvider.php index d4398fa..05ca87a 100644 --- a/src/DatabaseServiceProvider.php +++ b/src/DatabaseServiceProvider.php @@ -1,20 +1,19 @@ -publishes([$config_path => config_path('postgis.php')], 'postgis'); - $this->mergeConfigFrom($config_path, 'postgis'); + public function boot() + { + // Load the config + $config_path = __DIR__ . '/../config/postgis.php'; + $this->publishes([$config_path => config_path('postgis.php')], 'postgis'); + $this->mergeConfigFrom($config_path, 'postgis'); } /** diff --git a/src/Geometries/Factory.php b/src/Geometries/Factory.php index 6b51703..46eea79 100644 --- a/src/Geometries/Factory.php +++ b/src/Geometries/Factory.php @@ -1,44 +1,46 @@ -points) === 0) return false; + if (count($this->points) === 0) return false; return $this->points[0]->is3d(); } public function toWKT() { $wktType = 'LINESTRING'; - if($this->is3d()) $wktType .= ' Z'; + if ($this->is3d()) $wktType .= ' Z'; return sprintf('%s(%s)', $wktType, $this->toPairList()); } diff --git a/src/Geometries/MultiLineString.php b/src/Geometries/MultiLineString.php index ac0447a..87e08bc 100644 --- a/src/Geometries/MultiLineString.php +++ b/src/Geometries/MultiLineString.php @@ -1,4 +1,6 @@ -linestrings) === 0) return false; + if (count($this->linestrings) === 0) return false; return $this->linestrings[0]->is3d(); } public function toWKT() { $wktType = 'MULTILINESTRING'; - if($this->is3d()) $wktType .= ' Z'; + if ($this->is3d()) $wktType .= ' Z'; return sprintf('%s(%s)', $wktType, (string)$this); } diff --git a/src/Geometries/MultiPoint.php b/src/Geometries/MultiPoint.php index fea365e..c7e6805 100644 --- a/src/Geometries/MultiPoint.php +++ b/src/Geometries/MultiPoint.php @@ -1,4 +1,6 @@ -points) === 0) return false; + if (count($this->points) === 0) return false; return $this->points[0]->is3d(); } public function toWKT() { $wktType = 'MULTIPOINT'; - if($this->is3d()) $wktType .= ' Z'; + if ($this->is3d()) $wktType .= ' Z'; return sprintf('%s(%s)', $wktType, (string)$this); } diff --git a/src/Geometries/MultiPolygon.php b/src/Geometries/MultiPolygon.php index 80f7a9d..e8313f0 100644 --- a/src/Geometries/MultiPolygon.php +++ b/src/Geometries/MultiPolygon.php @@ -1,4 +1,6 @@ -polygons) === 0) return false; + if (count($this->polygons) === 0) return false; return $this->polygons[0]->is3d(); } public function toWKT() { $wktType = 'MULTIPOLYGON'; - if($this->is3d()) $wktType .= ' Z'; - return sprintf('%s(%s)', $wktType, (string) $this); + if ($this->is3d()) $wktType .= ' Z'; + return sprintf('%s(%s)', $wktType, (string)$this); } public function __toString() { return implode(',', array_map(function (Polygon $polygon) { - return sprintf('(%s)', (string) $polygon); + return sprintf('(%s)', (string)$polygon); }, $this->polygons)); } public static function fromString($wktArgument) { - $parts = preg_split('/(\)\s*\)\s*,\s*\(\s*\()/', $wktArgument, -1, PREG_SPLIT_DELIM_CAPTURE); + $parts = preg_split('/(\)\s*\)\s*,\s*\(\s*\()/', $wktArgument, -1, PREG_SPLIT_DELIM_CAPTURE); $polygons = static::assembleParts($parts); return new static(array_map(function ($polygonString) { @@ -99,7 +101,7 @@ public function getPolygons() protected static function assembleParts(array $parts) { $polygons = []; - $count = count($parts); + $count = count($parts); for ($i = 0; $i < $count; $i++) { if ($i % 2 !== 0) { diff --git a/src/Geometries/Point.php b/src/Geometries/Point.php index 0805f15..b406711 100644 --- a/src/Geometries/Point.php +++ b/src/Geometries/Point.php @@ -1,6 +1,6 @@ -getLng()) . ' ' . self::stringifyFloat($this->getLat()); - if($this->is3d()) { + if ($this->is3d()) { $pair .= ' ' . self::stringifyFloat($this->getAlt()); } return $pair; @@ -71,7 +71,7 @@ public static function fromPair($pair) $splits = explode(' ', trim($pair)); $lng = $splits[0]; $lat = $splits[1]; - if(count($splits) > 2) { + if (count($splits) > 2) { $alt = $splits[2]; } @@ -81,7 +81,7 @@ public static function fromPair($pair) public function toWKT() { $wktType = 'POINT'; - if($this->is3d()) $wktType .= ' Z'; + if ($this->is3d()) $wktType .= ' Z'; return sprintf('%s(%s)', $wktType, (string)$this); } @@ -103,7 +103,7 @@ public function __toString() public function jsonSerialize() { $position = [$this->getLng(), $this->getLat()]; - if($this->is3d()) $position[] = $this->getAlt(); + if ($this->is3d()) $position[] = $this->getAlt(); return new \GeoJson\Geometry\Point($position); } } diff --git a/src/Geometries/PointCollection.php b/src/Geometries/PointCollection.php index d77158d..8e60de5 100644 --- a/src/Geometries/PointCollection.php +++ b/src/Geometries/PointCollection.php @@ -1,4 +1,6 @@ -linestrings) === 0) return false; + if (count($this->linestrings) === 0) return false; return $this->linestrings[0]->is3d(); } public function toWKT() { $wktType = 'POLYGON'; - if($this->is3d()) $wktType .= ' Z'; + if ($this->is3d()) $wktType .= ' Z'; return sprintf('%s(%s)', $wktType, (string)$this); } @@ -26,7 +28,7 @@ public function jsonSerialize() { $linearrings = []; foreach ($this->linestrings as $linestring) { - $linearrings[] = new \GeoJson\Geometry\LinearRing($linestring->jsonSerialize()->getCoordinates()); + $linearrings[] = new LinearRing($linestring->jsonSerialize()->getCoordinates()); } return new \GeoJson\Geometry\Polygon($linearrings); diff --git a/src/PostgisConnection.php b/src/PostgisConnection.php index 81e4ece..746feb0 100644 --- a/src/PostgisConnection.php +++ b/src/PostgisConnection.php @@ -1,6 +1,11 @@ -withTablePrefix(new Schema\Grammars\PostgisGrammar); + return $this->withTablePrefix(new PostgisGrammar()); } public function getSchemaBuilder() { - if (is_null($this->schemaGrammar)) { + if ($this->schemaGrammar === null) { $this->useDefaultSchemaGrammar(); } From 951754b14980d622a54afbd8d8462d5ce9d1254b Mon Sep 17 00:00:00 2001 From: Max Staack Date: Wed, 11 Mar 2020 15:22:42 +0100 Subject: [PATCH 46/83] update readme --- README.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/README.md b/README.md index 193da53..02b1bd2 100644 --- a/README.md +++ b/README.md @@ -21,6 +21,9 @@ $table->polygon('myColumn'); ## Warning This Package has been moved to a new owner and aims for Laravel 6/7 and PHP 7 support only soon! + +Replace all your references to the new namespace: `MStaack\LaravelPostgis` + Thanks to : - https://github.com/njbarrett - https://github.com/phaza From dd9ddb9e42c0b54be9808d04947063f4f9e741ba Mon Sep 17 00:00:00 2001 From: Max Staack Date: Wed, 11 Mar 2020 15:23:37 +0100 Subject: [PATCH 47/83] test on push is enough --- .github/workflows/run-tests.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/run-tests.yml b/.github/workflows/run-tests.yml index c232c65..0fa975f 100644 --- a/.github/workflows/run-tests.yml +++ b/.github/workflows/run-tests.yml @@ -1,6 +1,6 @@ name: Test Suite -on: [push, pull_request] +on: [push] jobs: tests: From d065660a3a45bc96a721a41c17f09ee6cc25acb4 Mon Sep 17 00:00:00 2001 From: Max Staack Date: Wed, 11 Mar 2020 15:27:01 +0100 Subject: [PATCH 48/83] name --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 02b1bd2..f382581 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,5 @@ -Laravel postgis extension -========================= +Laravel Wrapper for PostgreSQL's Geo-Extension Postgis +====================================================== ![Build Status](https://github.com/mstaack/laravel-postgis/workflows/Test%20Suite/badge.svg) From a3bb4825245df4997b170a3e01b593909a95db7c Mon Sep 17 00:00:00 2001 From: Max Staack Date: Wed, 11 Mar 2020 15:32:16 +0100 Subject: [PATCH 49/83] update readme --- README.md | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index f382581..cf83596 100644 --- a/README.md +++ b/README.md @@ -15,14 +15,13 @@ $model->myPoint = new Point(1,2); //lat, long $table->polygon('myColumn'); ``` -## Versions -- Use 4.* for Laravel 5 -- Use 5.* for Laravel 6/7 - ## Warning This Package has been moved to a new owner and aims for Laravel 6/7 and PHP 7 support only soon! -Replace all your references to the new namespace: `MStaack\LaravelPostgis` +Replace all your references to the new namespace: +``` +MStaack\LaravelPostgis +``` Thanks to : - https://github.com/njbarrett @@ -32,7 +31,13 @@ Thanks to : Fluent in Laravel Packages and Postgres/Postgis? Consider contributing! We are looking for anyone that wants to help out! ## Installation +- Use 3.* for Laravel 5 +```bash +composer require "mstaack/laravel-postgis:3.*" +``` + +- Use 5.* for Laravel 6/7 ```bash composer require mstaack/laravel-postgis ``` From 87f252fa130b845d7b1149471df6b5020029a4b5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tom=C3=A1=C5=A1=20Vlk?= Date: Sun, 16 Aug 2020 01:22:25 +0200 Subject: [PATCH 50/83] fix connecting to database when registering package --- src/Connectors/ConnectionFactory.php | 5 +++-- src/PostgisConnection.php | 9 --------- 2 files changed, 3 insertions(+), 11 deletions(-) diff --git a/src/Connectors/ConnectionFactory.php b/src/Connectors/ConnectionFactory.php index 99b9beb..7585b27 100644 --- a/src/Connectors/ConnectionFactory.php +++ b/src/Connectors/ConnectionFactory.php @@ -1,5 +1,6 @@ container->bound($key = "db.connection.{$driver}")) { - return $this->container->make($key, [$connection, $database, $prefix, $config]); + if ($resolver = Connection::getResolver($driver)) { + return $resolver($connection, $database, $prefix, $config); } if ($driver === 'pgsql') { diff --git a/src/PostgisConnection.php b/src/PostgisConnection.php index 746feb0..6696bb1 100644 --- a/src/PostgisConnection.php +++ b/src/PostgisConnection.php @@ -7,15 +7,6 @@ class PostgisConnection extends PostgresConnection { - public function __construct($pdo, $database = '', $tablePrefix = '', array $config = []) - { - parent::__construct($pdo, $database, $tablePrefix, $config); - - // Prevent geography type fields from throwing a 'type not found' error. - $this->getDoctrineSchemaManager()->getDatabasePlatform()->registerDoctrineTypeMapping('geography', 'string'); - $this->getDoctrineSchemaManager()->getDatabasePlatform()->registerDoctrineTypeMapping('geometry', 'string'); - } - /** * Get the default schema grammar instance. * From 40224def3eb31afc7b56c6d8724d6dc4be2db3f7 Mon Sep 17 00:00:00 2001 From: Dena Date: Sat, 12 Sep 2020 12:44:09 +0430 Subject: [PATCH 51/83] Laravel 8 support --- README.md | 4 ++-- composer.json | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index cf83596..ffdced3 100644 --- a/README.md +++ b/README.md @@ -16,7 +16,7 @@ $table->polygon('myColumn'); ``` ## Warning -This Package has been moved to a new owner and aims for Laravel 6/7 and PHP 7 support only soon! +This Package has been moved to a new owner and aims for Laravel 6/7/8 and PHP 7 support only soon! Replace all your references to the new namespace: ``` @@ -37,7 +37,7 @@ Fluent in Laravel Packages and Postgres/Postgis? Consider contributing! We are l composer require "mstaack/laravel-postgis:3.*" ``` -- Use 5.* for Laravel 6/7 +- Use 5.* for Laravel 6/7/8 ```bash composer require mstaack/laravel-postgis ``` diff --git a/composer.json b/composer.json index 3d38307..b380404 100644 --- a/composer.json +++ b/composer.json @@ -3,13 +3,13 @@ "description": "Postgis extensions for laravel. Aims to make it easy to work with geometries from laravel models", "require": { "php": ">=7.1", - "illuminate/database": "^6.0|^7.0", + "illuminate/database": "^6.0|^7.0|^8.0", "geo-io/wkb-parser": "^1.0", "jmikola/geojson": "^1.0", "bosnadev/database": "0.20.*" }, "require-dev": { - "illuminate/pagination": "^6.0|^7.0", + "illuminate/pagination": "^6.0|^7.0|^8.0", "phpunit/phpunit": "^8.5", "mockery/mockery": "^1.3" }, From 700a3d5991b015dd7c0d03f24cb8c190f0e693b6 Mon Sep 17 00:00:00 2001 From: Dena Date: Mon, 14 Sep 2020 16:37:08 +0430 Subject: [PATCH 52/83] composer.json updated --- composer.json | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/composer.json b/composer.json index b380404..3b51d25 100644 --- a/composer.json +++ b/composer.json @@ -1,12 +1,26 @@ { "name": "mstaack/laravel-postgis", "description": "Postgis extensions for laravel. Aims to make it easy to work with geometries from laravel models", + "repositories": [ + { + "type":"package", + "package": { + "name": "bosnadev/database", + "version":"master", + "source": { + "url": "git@github.com:dena-a/database.git", + "type": "git", + "reference":"master" + } + } + } + ], "require": { "php": ">=7.1", "illuminate/database": "^6.0|^7.0|^8.0", "geo-io/wkb-parser": "^1.0", "jmikola/geojson": "^1.0", - "bosnadev/database": "0.20.*" + "bosnadev/database": "dev-master" }, "require-dev": { "illuminate/pagination": "^6.0|^7.0|^8.0", From 0c23d58c4b134c1223984bb019c5430992245fd4 Mon Sep 17 00:00:00 2001 From: Dena Date: Mon, 14 Sep 2020 16:39:47 +0430 Subject: [PATCH 53/83] undo composer.json updated --- composer.json | 16 +--------------- 1 file changed, 1 insertion(+), 15 deletions(-) diff --git a/composer.json b/composer.json index 3b51d25..b380404 100644 --- a/composer.json +++ b/composer.json @@ -1,26 +1,12 @@ { "name": "mstaack/laravel-postgis", "description": "Postgis extensions for laravel. Aims to make it easy to work with geometries from laravel models", - "repositories": [ - { - "type":"package", - "package": { - "name": "bosnadev/database", - "version":"master", - "source": { - "url": "git@github.com:dena-a/database.git", - "type": "git", - "reference":"master" - } - } - } - ], "require": { "php": ">=7.1", "illuminate/database": "^6.0|^7.0|^8.0", "geo-io/wkb-parser": "^1.0", "jmikola/geojson": "^1.0", - "bosnadev/database": "dev-master" + "bosnadev/database": "0.20.*" }, "require-dev": { "illuminate/pagination": "^6.0|^7.0|^8.0", From 1e9b896d71c2f71bcdd49fc86da30ec31c1857b7 Mon Sep 17 00:00:00 2001 From: Max Date: Thu, 22 Oct 2020 14:00:14 +0200 Subject: [PATCH 54/83] bump bosnadev dep --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index b380404..633e807 100644 --- a/composer.json +++ b/composer.json @@ -6,7 +6,7 @@ "illuminate/database": "^6.0|^7.0|^8.0", "geo-io/wkb-parser": "^1.0", "jmikola/geojson": "^1.0", - "bosnadev/database": "0.20.*" + "bosnadev/database": "^0.21" }, "require-dev": { "illuminate/pagination": "^6.0|^7.0|^8.0", From a9dc605bb99448e28076cb2d1ffa960363fdc28e Mon Sep 17 00:00:00 2001 From: George Buckingham Date: Thu, 28 Jan 2021 18:54:09 +0000 Subject: [PATCH 55/83] =?UTF-8?q?Create=20PostGIS=20extension=20if=20it=20?= =?UTF-8?q?doesn=E2=80=99t=20exist?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/Schema/Blueprint.php | 12 ++++++++++++ src/Schema/Builder.php | 19 +++++++++++++++++-- src/Schema/Grammars/PostgisGrammar.php | 10 ++++++++++ tests/Schema/BlueprintTest.php | 9 +++++++++ tests/Schema/Grammars/PostgisGrammarTest.php | 10 ++++++++++ 5 files changed, 58 insertions(+), 2 deletions(-) diff --git a/src/Schema/Blueprint.php b/src/Schema/Blueprint.php index e31b38f..836bfab 100644 --- a/src/Schema/Blueprint.php +++ b/src/Schema/Blueprint.php @@ -126,9 +126,21 @@ public function enablePostgis() return $this->addCommand('enablePostgis'); } + /** + * Enable postgis on this database. + * Will create the extension in the database if it doesn't already exist. + * + * @return \Illuminate\Support\Fluent + */ + public function enablePostgisIfNotExists() + { + return $this->addCommand('enablePostgisIfNotExists'); + } + /** * Disable postgis on this database. * WIll drop the extension in the database. + * * @return \Illuminate\Support\Fluent */ public function disablePostgis() diff --git a/src/Schema/Builder.php b/src/Schema/Builder.php index 39d4b19..b0c3825 100644 --- a/src/Schema/Builder.php +++ b/src/Schema/Builder.php @@ -17,7 +17,8 @@ public function createBlueprint($table, Closure $callback = null) } /** - * Enable foreign key constraints. + * Enable postgis on this database. + * Will create the extension in the database. * * @return bool */ @@ -29,7 +30,21 @@ public function enablePostgis() } /** - * Disable foreign key constraints. + * Enable postgis on this database. + * Will create the extension in the database if it doesn't already exist. + * + * @return bool + */ + public function enablePostgisIfNotExists() + { + return $this->connection->statement( + $this->grammar->compileEnablePostgisIfNotExists() + ); + } + + /** + * Disable postgis on this database. + * WIll drop the extension in the database. * * @return bool */ diff --git a/src/Schema/Grammars/PostgisGrammar.php b/src/Schema/Grammars/PostgisGrammar.php index 336161f..7ba17a9 100644 --- a/src/Schema/Grammars/PostgisGrammar.php +++ b/src/Schema/Grammars/PostgisGrammar.php @@ -133,6 +133,16 @@ public function compileEnablePostgis() return 'CREATE EXTENSION postgis'; } + /** + * Adds a statement to create the postgis extension, if it doesn't already exist + * + * @return string + */ + public function compileEnablePostgisIfNotExists() + { + return 'CREATE EXTENSION IF NOT EXISTS postgis'; + } + /** * Adds a statement to drop the postgis extension * diff --git a/tests/Schema/BlueprintTest.php b/tests/Schema/BlueprintTest.php index cc898c9..0a5b8b7 100644 --- a/tests/Schema/BlueprintTest.php +++ b/tests/Schema/BlueprintTest.php @@ -90,6 +90,15 @@ public function testEnablePostgis() $this->blueprint->enablePostgis(); } + public function testEnablePostgisIfNotExists() + { + $this->blueprint + ->shouldReceive('addCommand') + ->with('enablePostgis', []); + + $this->blueprint->enablePostgisIfNotExists(); + } + public function testDisablePostgis() { $this->blueprint diff --git a/tests/Schema/Grammars/PostgisGrammarTest.php b/tests/Schema/Grammars/PostgisGrammarTest.php index 0b1761f..1a296d0 100644 --- a/tests/Schema/Grammars/PostgisGrammarTest.php +++ b/tests/Schema/Grammars/PostgisGrammarTest.php @@ -274,6 +274,16 @@ public function testEnablePostgis() $this->assertStringContainsString('CREATE EXTENSION postgis', $statements[0]); } + public function testEnablePostgisIfNotExists() + { + $blueprint = new Blueprint('test'); + $blueprint->enablePostgisIfNotExists(); + $statements = $blueprint->toSql($this->getConnection(), $this->getGrammar()); + + $this->assertCount(1, $statements);; + $this->assertStringContainsString('CREATE EXTENSION IF NOT EXISTS postgis', $statements[0]); + } + public function testDisablePostgis() { $blueprint = new Blueprint('test'); From dbc285ac04f3bb3394d1fe16ad07566e85407213 Mon Sep 17 00:00:00 2001 From: George Buckingham Date: Thu, 28 Jan 2021 19:13:08 +0000 Subject: [PATCH 56/83] Drop PostGIS extension if it exists --- src/Schema/Blueprint.php | 11 +++++++++++ src/Schema/Builder.php | 13 +++++++++++++ src/Schema/Grammars/PostgisGrammar.php | 10 ++++++++++ tests/Schema/BlueprintTest.php | 9 +++++++++ tests/Schema/Grammars/PostgisGrammarTest.php | 10 ++++++++++ 5 files changed, 53 insertions(+) diff --git a/src/Schema/Blueprint.php b/src/Schema/Blueprint.php index 836bfab..a7babf9 100644 --- a/src/Schema/Blueprint.php +++ b/src/Schema/Blueprint.php @@ -148,4 +148,15 @@ public function disablePostgis() return $this->addCommand('disablePostgis'); } + /** + * Disable postgis on this database. + * WIll drop the extension in the database if it exists. + * + * @return \Illuminate\Support\Fluent + */ + public function disablePostgisIfExists() + { + return $this->addCommand('disablePostgisIfExists'); + } + } diff --git a/src/Schema/Builder.php b/src/Schema/Builder.php index b0c3825..52b78ed 100644 --- a/src/Schema/Builder.php +++ b/src/Schema/Builder.php @@ -54,4 +54,17 @@ public function disablePostgis() $this->grammar->compileDisablePostgis() ); } + + /** + * Disable postgis on this database. + * WIll drop the extension in the database if it exists. + * + * @return bool + */ + public function disablePostgisIfExists() + { + return $this->connection->statement( + $this->grammar->compileDisablePostgisIfExists() + ); + } } diff --git a/src/Schema/Grammars/PostgisGrammar.php b/src/Schema/Grammars/PostgisGrammar.php index 7ba17a9..6bef2ed 100644 --- a/src/Schema/Grammars/PostgisGrammar.php +++ b/src/Schema/Grammars/PostgisGrammar.php @@ -153,6 +153,16 @@ public function compileDisablePostgis() return 'DROP EXTENSION postgis'; } + /** + * Adds a statement to drop the postgis extension, if it exists + * + * @return string + */ + public function compileDisablePostgisIfExists() + { + return 'DROP EXTENSION IF EXISTS postgis'; + } + /** * Adds a statement to add a geometry column * diff --git a/tests/Schema/BlueprintTest.php b/tests/Schema/BlueprintTest.php index 0a5b8b7..fcd6521 100644 --- a/tests/Schema/BlueprintTest.php +++ b/tests/Schema/BlueprintTest.php @@ -107,4 +107,13 @@ public function testDisablePostgis() $this->blueprint->disablePostgis(); } + + public function testDisablePostgisIfExists() + { + $this->blueprint + ->shouldReceive('addCommand') + ->with('disablePostgis', []); + + $this->blueprint->disablePostgisIfExists(); + } } diff --git a/tests/Schema/Grammars/PostgisGrammarTest.php b/tests/Schema/Grammars/PostgisGrammarTest.php index 1a296d0..3a9927a 100644 --- a/tests/Schema/Grammars/PostgisGrammarTest.php +++ b/tests/Schema/Grammars/PostgisGrammarTest.php @@ -294,6 +294,16 @@ public function testDisablePostgis() $this->assertStringContainsString('DROP EXTENSION postgis', $statements[0]); } + public function testDisablePostgisIfExists() + { + $blueprint = new Blueprint('test'); + $blueprint->disablePostgisIfExists(); + $statements = $blueprint->toSql($this->getConnection(), $this->getGrammar()); + + $this->assertCount(1, $statements);; + $this->assertStringContainsString('DROP EXTENSION IF EXISTS postgis', $statements[0]); + } + /** * @return Connection */ From f343b5dd02f913f5c57ab14da7db885499aececa Mon Sep 17 00:00:00 2001 From: George Buckingham Date: Thu, 28 Jan 2021 19:55:36 +0000 Subject: [PATCH 57/83] Add instructions to README for enabling PostGIS --- README.md | 50 ++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 48 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index ffdced3..dbcb8fa 100644 --- a/README.md +++ b/README.md @@ -50,11 +50,57 @@ If you are using Laravel < 5.5, you also need to add the DatabaseServiceProvider ``` ## Usage -First of all, make sure to enable postgis. +To start, ensure you have PostGIS enabled in your database - you can do this in a Laravel migration or manually via SQL. + +### Enable PostGIS via a Laravel migration + +Create a new migration file by running + + php artisan make:migration enable_postgis + +Update the newly created migration file to call the `enablePostgisIfNotExists()` and `disablePostgisIfExists()` methods on the `Schema` facade. For example: + +```PHP + Date: Tue, 16 Feb 2021 21:13:52 +0000 Subject: [PATCH 58/83] fixes multipoint fromwkt without nested parenthesis (default with geoserver st_astext), the testFromWKTWithoutInnerParentesis in tests/Geometries/MultiPointTest shows the error, this could probably be done with the preg_match_all but I'm not that good at regex --- src/Geometries/MultiPoint.php | 7 +++++++ tests/Geometries/MultiPointTest.php | 8 ++++++++ 2 files changed, 15 insertions(+) diff --git a/src/Geometries/MultiPoint.php b/src/Geometries/MultiPoint.php index c7e6805..85e548d 100644 --- a/src/Geometries/MultiPoint.php +++ b/src/Geometries/MultiPoint.php @@ -43,6 +43,13 @@ public static function fromWKT($wkt) public static function fromString($wktArgument) { + if (!strpos(trim($wktArgument), '(')) { + $points = explode(',', $wktArgument); + $wktArgument = implode(", ", array_map(function ($pair) { + return '(' . trim($pair) . ')'; + }, $points)); + }; + $matches = []; preg_match_all('/\(\s*(\d+\s+\d+(\s+\d+)?)\s*\)/', trim($wktArgument), $matches); diff --git a/tests/Geometries/MultiPointTest.php b/tests/Geometries/MultiPointTest.php index bbecb02..0e5b16f 100644 --- a/tests/Geometries/MultiPointTest.php +++ b/tests/Geometries/MultiPointTest.php @@ -16,6 +16,14 @@ public function testFromWKT() $this->assertEquals(3, $multipoint->count()); } + public function testFromWKTWithoutInnerParentesis() + { + $multipoint = MultiPoint::fromWKT('MULTIPOINT(1 1, 2 1, 2 2)'); + $this->assertInstanceOf(MultiPoint::class, $multipoint); + + $this->assertEquals(3, $multipoint->count()); + } + public function testFromWKT3d() { $multipoint = MultiPoint::fromWKT('MULTIPOINT Z((1 1 1),(2 1 3),(2 2 2))'); From ab24f9fbcb9063c4f04baf7415fa72ea745410a7 Mon Sep 17 00:00:00 2001 From: Etienne Date: Tue, 16 Feb 2021 21:30:15 +0000 Subject: [PATCH 59/83] rename testFromWKTWithoutNestedParentesis --- tests/Geometries/MultiPointTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/Geometries/MultiPointTest.php b/tests/Geometries/MultiPointTest.php index 0e5b16f..88587e1 100644 --- a/tests/Geometries/MultiPointTest.php +++ b/tests/Geometries/MultiPointTest.php @@ -16,7 +16,7 @@ public function testFromWKT() $this->assertEquals(3, $multipoint->count()); } - public function testFromWKTWithoutInnerParentesis() + public function testFromWKTWithoutNestedParentesis() { $multipoint = MultiPoint::fromWKT('MULTIPOINT(1 1, 2 1, 2 2)'); $this->assertInstanceOf(MultiPoint::class, $multipoint); From 7cf7e58e37739259b76cac604158ab13d29c3adc Mon Sep 17 00:00:00 2001 From: Etienne Date: Tue, 16 Feb 2021 21:37:11 +0000 Subject: [PATCH 60/83] creates the test for 3D points without nested parentesis --- tests/Geometries/MultiPointTest.php | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/tests/Geometries/MultiPointTest.php b/tests/Geometries/MultiPointTest.php index 88587e1..a8bd363 100644 --- a/tests/Geometries/MultiPointTest.php +++ b/tests/Geometries/MultiPointTest.php @@ -32,6 +32,14 @@ public function testFromWKT3d() $this->assertEquals(3, $multipoint->count()); } + public function testFromWKT3dWithoutNestedParentesis() + { + $multipoint = MultiPoint::fromWKT('MULTIPOINT Z(1 1 1, 2 1 3, 2 2 2)'); + $this->assertInstanceOf(MultiPoint::class, $multipoint); + + $this->assertEquals(3, $multipoint->count()); + } + public function testToWKT() { $collection = [new Point(1, 1), new Point(1, 2), new Point(2, 2)]; From e51ca77ca02871d06477ef60a6fb12c0ff55a15d Mon Sep 17 00:00:00 2001 From: Etienne Date: Tue, 16 Feb 2021 22:56:11 +0000 Subject: [PATCH 61/83] replaces \d in with [+-]?([0-9]+([.][0-9]*)?|[.][0-9]+) to support floating point values --- src/Geometries/MultiPoint.php | 4 ++-- tests/Geometries/MultiPointTest.php | 8 ++++++++ 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/src/Geometries/MultiPoint.php b/src/Geometries/MultiPoint.php index 85e548d..d7a7421 100644 --- a/src/Geometries/MultiPoint.php +++ b/src/Geometries/MultiPoint.php @@ -45,13 +45,13 @@ public static function fromString($wktArgument) { if (!strpos(trim($wktArgument), '(')) { $points = explode(',', $wktArgument); - $wktArgument = implode(", ", array_map(function ($pair) { + $wktArgument = implode(',', array_map(function ($pair) { return '(' . trim($pair) . ')'; }, $points)); }; $matches = []; - preg_match_all('/\(\s*(\d+\s+\d+(\s+\d+)?)\s*\)/', trim($wktArgument), $matches); + preg_match_all('/\(\s*([+-]?([0-9]+([.][0-9]*)?|[.][0-9]+)+\s+[+-]?([0-9]+([.][0-9]*)?|[.][0-9]+)+(\s+[+-]?([0-9]+([.][0-9]*)?|[.][0-9]+)+)?)\s*\)/', trim($wktArgument), $matches); if (count($matches) < 2) { return new static([]); diff --git a/tests/Geometries/MultiPointTest.php b/tests/Geometries/MultiPointTest.php index a8bd363..6f24f85 100644 --- a/tests/Geometries/MultiPointTest.php +++ b/tests/Geometries/MultiPointTest.php @@ -16,6 +16,14 @@ public function testFromWKT() $this->assertEquals(3, $multipoint->count()); } + public function testFromWKTWithFloatingPoint() + { + $multipoint = MultiPoint::fromWKT('MULTIPOINT((1.0 1.0),(2.0 1.0),(2.0 2.0))'); + $this->assertInstanceOf(MultiPoint::class, $multipoint); + + $this->assertEquals(3, $multipoint->count()); + } + public function testFromWKTWithoutNestedParentesis() { $multipoint = MultiPoint::fromWKT('MULTIPOINT(1 1, 2 1, 2 2)'); From 858890c3c0743d86417c67625f0e9036586d2122 Mon Sep 17 00:00:00 2001 From: Alexander von Studnitz Date: Wed, 2 Jun 2021 11:53:01 +0200 Subject: [PATCH 62/83] Add publishable migration --- database/migrations/enable_postgis.php.stub | 27 +++++++++++++++++++++ src/DatabaseServiceProvider.php | 7 ++++++ 2 files changed, 34 insertions(+) create mode 100644 database/migrations/enable_postgis.php.stub diff --git a/database/migrations/enable_postgis.php.stub b/database/migrations/enable_postgis.php.stub new file mode 100644 index 0000000..b5e1ab7 --- /dev/null +++ b/database/migrations/enable_postgis.php.stub @@ -0,0 +1,27 @@ +publishes([$config_path => config_path('postgis.php')], 'postgis'); + + if (!class_exists('EnablePostgis')) { + $this->publishes([ + __DIR__ . '/../database/migrations/enable_postgis.php.stub' => database_path('migrations/'.date('Y_m_d_His', time()).'_enable_postgis.php'), + ], 'migrations'); + } + $this->mergeConfigFrom($config_path, 'postgis'); } From 5be106f58a0406bb03676afdc33325d9c9f3f00d Mon Sep 17 00:00:00 2001 From: Alexander von Studnitz Date: Wed, 2 Jun 2021 11:57:05 +0200 Subject: [PATCH 63/83] Update README with easier migrations installation --- README.md | 40 ++++++++-------------------------------- 1 file changed, 8 insertions(+), 32 deletions(-) diff --git a/README.md b/README.md index dbcb8fa..70322a8 100644 --- a/README.md +++ b/README.md @@ -54,45 +54,21 @@ To start, ensure you have PostGIS enabled in your database - you can do this in ### Enable PostGIS via a Laravel migration -Create a new migration file by running +You need to publish the migration to easily enable PostGIS: - php artisan make:migration enable_postgis - -Update the newly created migration file to call the `enablePostgisIfNotExists()` and `disablePostgisIfExists()` methods on the `Schema` facade. For example: - -```PHP - Date: Wed, 12 Jan 2022 13:50:52 +0000 Subject: [PATCH 64/83] Adds use InvalidArgumentException to Geometries/MutltiPoint --- src/Geometries/MultiPoint.php | 1 + 1 file changed, 1 insertion(+) mode change 100644 => 100755 src/Geometries/MultiPoint.php diff --git a/src/Geometries/MultiPoint.php b/src/Geometries/MultiPoint.php old mode 100644 new mode 100755 index d7a7421..c94fbc1 --- a/src/Geometries/MultiPoint.php +++ b/src/Geometries/MultiPoint.php @@ -1,6 +1,7 @@ Date: Thu, 27 Jan 2022 14:45:45 +0000 Subject: [PATCH 65/83] Add Laravel 9 support --- README.md | 4 ++-- composer.json | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 70322a8..cebb0a0 100644 --- a/README.md +++ b/README.md @@ -16,7 +16,7 @@ $table->polygon('myColumn'); ``` ## Warning -This Package has been moved to a new owner and aims for Laravel 6/7/8 and PHP 7 support only soon! +This Package has been moved to a new owner and aims for Laravel 6/7/8/9 and PHP 7 support only soon! Replace all your references to the new namespace: ``` @@ -37,7 +37,7 @@ Fluent in Laravel Packages and Postgres/Postgis? Consider contributing! We are l composer require "mstaack/laravel-postgis:3.*" ``` -- Use 5.* for Laravel 6/7/8 +- Use 5.* for Laravel 6/7/8/9 ```bash composer require mstaack/laravel-postgis ``` diff --git a/composer.json b/composer.json index 633e807..5688526 100644 --- a/composer.json +++ b/composer.json @@ -3,13 +3,13 @@ "description": "Postgis extensions for laravel. Aims to make it easy to work with geometries from laravel models", "require": { "php": ">=7.1", - "illuminate/database": "^6.0|^7.0|^8.0", + "illuminate/database": "^6.0|^7.0|^8.0|^9.0", "geo-io/wkb-parser": "^1.0", "jmikola/geojson": "^1.0", "bosnadev/database": "^0.21" }, "require-dev": { - "illuminate/pagination": "^6.0|^7.0|^8.0", + "illuminate/pagination": "^6.0|^7.0|^8.0|^9.0", "phpunit/phpunit": "^8.5", "mockery/mockery": "^1.3" }, From 7e5527a9bd638fd9ba7be0509836c43528cf1ff5 Mon Sep 17 00:00:00 2001 From: Roberto Santana Date: Thu, 21 Apr 2022 10:04:40 +0200 Subject: [PATCH 66/83] Added support for branch master on bosnadev/database This allows to update to Laravel 9. bosnadev/database has added support to illuminate/database 9.0 on master branch --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 5688526..5da9db1 100644 --- a/composer.json +++ b/composer.json @@ -6,7 +6,7 @@ "illuminate/database": "^6.0|^7.0|^8.0|^9.0", "geo-io/wkb-parser": "^1.0", "jmikola/geojson": "^1.0", - "bosnadev/database": "^0.21" + "bosnadev/database": "^0.21|master" }, "require-dev": { "illuminate/pagination": "^6.0|^7.0|^8.0|^9.0", From b309f08f7dccd48b95f1d8b8f92fa400e29ce18e Mon Sep 17 00:00:00 2001 From: Roy van der Veen Date: Mon, 9 May 2022 13:38:01 +0200 Subject: [PATCH 67/83] Add linestringz --- src/Schema/Blueprint.php | 11 +++++++++++ src/Schema/Grammars/PostgisGrammar.php | 11 +++++++++++ 2 files changed, 22 insertions(+) diff --git a/src/Schema/Blueprint.php b/src/Schema/Blueprint.php index a7babf9..de389a2 100644 --- a/src/Schema/Blueprint.php +++ b/src/Schema/Blueprint.php @@ -68,6 +68,17 @@ public function linestring($column, $geomtype = 'GEOGRAPHY', $srid = '4326') return $this->addColumn('linestring', $column, compact('geomtype', 'srid')); } + /** + * Add a linestringz column on the table + * + * @param $column + * @return \Illuminate\Support\Fluent + */ + public function linestringz($column, $geomtype = 'GEOGRAPHY', $srid = '4326') + { + return $this->addColumn('linestringz', $column, compact('geomtype', 'srid')); + } + /** * Add a multilinestring column on the table * diff --git a/src/Schema/Grammars/PostgisGrammar.php b/src/Schema/Grammars/PostgisGrammar.php index 6bef2ed..d445280 100644 --- a/src/Schema/Grammars/PostgisGrammar.php +++ b/src/Schema/Grammars/PostgisGrammar.php @@ -76,6 +76,17 @@ public function typeLinestring(Fluent $column) return $this->createTypeDefinition($column, 'LINESTRING'); } + /** + * Adds a statement to add a linestringz geometry column + * + * @param \Illuminate\Support\Fluent $column + * @return string + */ + public function typeLinestringZ(Fluent $column) + { + return $this->createTypeDefinition($column, 'LINESTRINGZ'); + } + /** * Adds a statement to add a multilinestring geometry column * From 15d88e4511017f287b46821a37fb51928722fe18 Mon Sep 17 00:00:00 2001 From: Roy van der Veen Date: Mon, 16 May 2022 14:44:31 +0200 Subject: [PATCH 68/83] Add pointz --- src/Schema/Blueprint.php | 11 +++++++++++ src/Schema/Grammars/PostgisGrammar.php | 11 +++++++++++ 2 files changed, 22 insertions(+) diff --git a/src/Schema/Blueprint.php b/src/Schema/Blueprint.php index de389a2..3adfd44 100644 --- a/src/Schema/Blueprint.php +++ b/src/Schema/Blueprint.php @@ -13,6 +13,17 @@ public function point($column, $geomtype = 'GEOGRAPHY', $srid = '4326') return $this->addColumn('point', $column, compact('geomtype', 'srid')); } + /** + * Add a point column on the table + * + * @param $column + * @return \Illuminate\Support\Fluent + */ + public function pointz($column, $geomtype = 'GEOGRAPHY', $srid = '4326') + { + return $this->addColumn('pointz', $column, compact('geomtype', 'srid')); + } + /** * Add a multipoint column on the table * diff --git a/src/Schema/Grammars/PostgisGrammar.php b/src/Schema/Grammars/PostgisGrammar.php index d445280..9a67309 100644 --- a/src/Schema/Grammars/PostgisGrammar.php +++ b/src/Schema/Grammars/PostgisGrammar.php @@ -21,6 +21,17 @@ public function typePoint(Fluent $column) return $this->createTypeDefinition($column, 'POINT'); } + /** + * Adds a statement to add a pointz geometry column + * + * @param \Illuminate\Support\Fluent $column + * @return string + */ + public function typePointZ(Fluent $column) + { + return $this->createTypeDefinition($column, 'POINTZ'); + } + /** * Adds a statement to add a point geometry column * From 577f0d66226932bb66ed078ba70333b068369614 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Roger=20Vil=C3=A0?= Date: Tue, 31 May 2022 23:01:32 +0200 Subject: [PATCH 69/83] import missing GeometryCollection --- src/Eloquent/PostgisTrait.php | 1 + 1 file changed, 1 insertion(+) diff --git a/src/Eloquent/PostgisTrait.php b/src/Eloquent/PostgisTrait.php index 1112d21..b5363ff 100644 --- a/src/Eloquent/PostgisTrait.php +++ b/src/Eloquent/PostgisTrait.php @@ -6,6 +6,7 @@ use MStaack\LaravelPostgis\Exceptions\PostgisTypesMalformedException; use MStaack\LaravelPostgis\Exceptions\UnsupportedGeomtypeException; use MStaack\LaravelPostgis\Geometries\Geometry; +use MStaack\LaravelPostgis\Geometries\GeometryCollection; use MStaack\LaravelPostgis\Geometries\GeometryInterface; use MStaack\LaravelPostgis\Schema\Grammars\PostgisGrammar; From effdefae83e93792b2ff2fc3783bf7a8af511b72 Mon Sep 17 00:00:00 2001 From: Scott Limmer Date: Sun, 12 Jun 2022 16:55:32 +1000 Subject: [PATCH 70/83] Added support for custom float precision to Point. Constructor reads value from config/postgis.php:precision or defaults to 6 (the default precision for sprintf). It is not anticipated that users will want to customise precision for an individual point, so no argument has been added to the constructor signature. A setter is provided for precision, though this is primarily to enable tests. If users do need to set precision for an individual point, the setter may be used. stringifyFloat has been converted to dynamic function to ease testing. It was only ever called from a non-static context anyway. --- src/Geometries/Point.php | 23 +++++++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) diff --git a/src/Geometries/Point.php b/src/Geometries/Point.php index b406711..020f70c 100644 --- a/src/Geometries/Point.php +++ b/src/Geometries/Point.php @@ -7,12 +7,26 @@ class Point extends Geometry protected $lat; protected $lng; protected $alt; + protected $precision; public function __construct($lat, $lng, $alt = null) { $this->lat = (float)$lat; $this->lng = (float)$lng; $this->alt = isset($alt) ? (float)$alt : null; + $this->setPrecision( + function_exists('config') ? config('postgis.precision') : 6 + ); + } + + public function setPrecision($precision) + { + $precision = filter_var($precision, FILTER_VALIDATE_INT); + if (!is_int($precision)) { + throw new \UnexpectedValueException('Precision must be an integer'); + } + + $this->precision = $precision; } public function getLat() @@ -52,17 +66,18 @@ public function is3d() public function toPair() { - $pair = self::stringifyFloat($this->getLng()) . ' ' . self::stringifyFloat($this->getLat()); + $pair = $this->stringifyFloat($this->getLng()) . ' ' . $this->stringifyFloat($this->getLat()); if ($this->is3d()) { - $pair .= ' ' . self::stringifyFloat($this->getAlt()); + $pair .= ' ' . $this->stringifyFloat($this->getAlt()); } return $pair; } - private static function stringifyFloat($float) + private function stringifyFloat($float) { // normalized output among locales - return rtrim(rtrim(sprintf('%F', $float), '0'), '.'); + + return rtrim(rtrim(sprintf("%.{$this->precision}F", $float), '0'), '.'); } public static function fromPair($pair) From b447927120eb880f81bc07d47a7d2b2d2e94a680 Mon Sep 17 00:00:00 2001 From: Scott Limmer Date: Sun, 12 Jun 2022 16:56:00 +1000 Subject: [PATCH 71/83] Added tests for customisable Point precision --- tests/Geometries/PointTest.php | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/tests/Geometries/PointTest.php b/tests/Geometries/PointTest.php index 97ecaee..f12a399 100644 --- a/tests/Geometries/PointTest.php +++ b/tests/Geometries/PointTest.php @@ -126,4 +126,20 @@ public function testJsonSerialize3d() $this->assertInstanceOf(\GeoJson\Geometry\Point::class, $point->jsonSerialize()); $this->assertSame('{"type":"Point","coordinates":[3.4,1.2,5.6]}', json_encode($point)); } + + public function testPointPrecisionDefault() + { + $point = new Point(-37.8745505,144.9102885,12.38); + + $this->assertSame('144.910289 -37.87455 12.38', $point->toPair()); + + } + + public function testPointPrecision10() + { + $point = new Point(-37.87455051578,144.91028850798,7.38257341563); + $point->setPrecision(10); + + $this->assertSame('144.910288508 -37.8745505158 7.3825734156', $point->toPair()); + } } From 06f8d0615314766c0cd3f1089f919bb1e192d4f7 Mon Sep 17 00:00:00 2001 From: Scott Limmer Date: Sun, 12 Jun 2022 16:56:14 +1000 Subject: [PATCH 72/83] Added sensible default to config for customisable Point precision --- config/postgis.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/config/postgis.php b/config/postgis.php index 696cd6c..3186cd7 100644 --- a/config/postgis.php +++ b/config/postgis.php @@ -1,5 +1,6 @@ 'public' // Schema for the Postgis extension + 'schema' => 'public', // Schema for the Postgis extension, + 'precision' => 6, // Control precision of floats in stringifyFloat ]; From a0755be7e373b43e90f984dd432d6d7a7025bc30 Mon Sep 17 00:00:00 2001 From: Scott Limmer Date: Sun, 12 Jun 2022 17:02:07 +1000 Subject: [PATCH 73/83] Updated readme for customisable Point precision --- README.md | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/README.md b/README.md index cebb0a0..9412f6c 100644 --- a/README.md +++ b/README.md @@ -233,3 +233,22 @@ Available geometry classes: * Polygon * MultiPolygon * GeometryCollection + +## Publishing config +A configuration file exists for overriding default values. To add to your project, run: + +```sh +php artisan vendor:publish --provider="MStaack\LaravelPostgis\DatabaseServiceProvider" --tag="postgis" +``` +### Coordinate precision +The precision of stored/displayed coordinated can be customised in the config. + + +```php +# config/postgis.php +return [ + ... + 'precision' => 6, +]; +``` +See http://wiki.gis.com/wiki/index.php/Decimal_degrees#Accuracy for more information \ No newline at end of file From 50cc71cd49dc5a721cb9b444754c4bf9c9fc4ce3 Mon Sep 17 00:00:00 2001 From: tdomy Date: Sat, 16 Jul 2022 18:36:10 +0900 Subject: [PATCH 74/83] Added return type --- src/Geometries/GeometryCollection.php | 4 ++-- src/Geometries/LineString.php | 2 +- src/Geometries/MultiLineString.php | 2 +- src/Geometries/MultiPoint.php | 2 +- src/Geometries/MultiPolygon.php | 4 ++-- src/Geometries/Point.php | 2 +- src/Geometries/PointCollection.php | 13 +++++++------ 7 files changed, 15 insertions(+), 14 deletions(-) diff --git a/src/Geometries/GeometryCollection.php b/src/Geometries/GeometryCollection.php index 1ad0e45..b519ba7 100644 --- a/src/Geometries/GeometryCollection.php +++ b/src/Geometries/GeometryCollection.php @@ -69,7 +69,7 @@ function ($geometry_string) { ); } - public function count() + public function count(): int { return count($this->geometries); } @@ -79,7 +79,7 @@ public function count() * * @return \GeoJson\Geometry\GeometryCollection */ - public function jsonSerialize() + public function jsonSerialize(): \GeoJson\Geometry\GeometryCollection { $geometries = []; foreach ($this->geometries as $geometry) { diff --git a/src/Geometries/LineString.php b/src/Geometries/LineString.php index 6d489be..c8ced64 100644 --- a/src/Geometries/LineString.php +++ b/src/Geometries/LineString.php @@ -44,7 +44,7 @@ public function __toString() * * @return \GeoJson\Geometry\LineString */ - public function jsonSerialize() + public function jsonSerialize(): \GeoJson\Geometry\LineString { $points = []; foreach ($this->points as $point) { diff --git a/src/Geometries/MultiLineString.php b/src/Geometries/MultiLineString.php index 87e08bc..b3b82a7 100644 --- a/src/Geometries/MultiLineString.php +++ b/src/Geometries/MultiLineString.php @@ -68,7 +68,7 @@ public function __toString() }, $this->getLineStrings())); } - public function count() + public function count(): int { return count($this->linestrings); } diff --git a/src/Geometries/MultiPoint.php b/src/Geometries/MultiPoint.php index c94fbc1..465047c 100755 --- a/src/Geometries/MultiPoint.php +++ b/src/Geometries/MultiPoint.php @@ -77,7 +77,7 @@ public function __toString() * * @return \GeoJson\Geometry\MultiPoint */ - public function jsonSerialize() + public function jsonSerialize(): \GeoJson\Geometry\MultiPoint { $points = []; foreach ($this->points as $point) { diff --git a/src/Geometries/MultiPolygon.php b/src/Geometries/MultiPolygon.php index e8313f0..56c205d 100644 --- a/src/Geometries/MultiPolygon.php +++ b/src/Geometries/MultiPolygon.php @@ -67,7 +67,7 @@ public static function fromString($wktArgument) *

* The return value is cast to an integer. */ - public function count() + public function count(): int { return count($this->polygons); } @@ -121,7 +121,7 @@ protected static function assembleParts(array $parts) * * @return \GeoJson\Geometry\MultiPolygon */ - public function jsonSerialize() + public function jsonSerialize(): \GeoJson\Geometry\MultiPolygon { $polygons = []; foreach ($this->polygons as $polygon) { diff --git a/src/Geometries/Point.php b/src/Geometries/Point.php index 020f70c..1199447 100644 --- a/src/Geometries/Point.php +++ b/src/Geometries/Point.php @@ -115,7 +115,7 @@ public function __toString() * * @return \GeoJson\Geometry\Point */ - public function jsonSerialize() + public function jsonSerialize(): \GeoJson\Geometry\Point { $position = [$this->getLng(), $this->getLat()]; if ($this->is3d()) $position[] = $this->getAlt(); diff --git a/src/Geometries/PointCollection.php b/src/Geometries/PointCollection.php index 8e60de5..1e6e3ca 100644 --- a/src/Geometries/PointCollection.php +++ b/src/Geometries/PointCollection.php @@ -9,6 +9,7 @@ use InvalidArgumentException; use IteratorAggregate; use JsonSerializable; +use Traversable; abstract class PointCollection implements IteratorAggregate, Arrayable, ArrayAccess, Countable, JsonSerializable { @@ -46,7 +47,7 @@ public function toArray() return $this->points; } - public function getIterator() + public function getIterator(): Traversable { return new ArrayIterator($this->points); } @@ -70,7 +71,7 @@ public function insertPoint($index, Point $point) array_splice($this->points, $offset, 0, [$point]); } - public function offsetExists($offset) + public function offsetExists($offset): bool { return isset($this->points[$offset]); } @@ -79,12 +80,12 @@ public function offsetExists($offset) * @param mixed $offset * @return null|Point */ - public function offsetGet($offset) + public function offsetGet($offset): ?Point { return $this->offsetExists($offset) ? $this->points[$offset] : null; } - public function offsetSet($offset, $value) + public function offsetSet($offset, $value): void { if (!($value instanceof Point)) { throw new InvalidArgumentException('$value must be an instance of Point'); @@ -97,12 +98,12 @@ public function offsetSet($offset, $value) } } - public function offsetUnset($offset) + public function offsetUnset($offset): void { unset($this->points[$offset]); } - public function count() + public function count(): int { return count($this->points); } From 940855e6de9ccb9e69ab1c59c1c9c5e16d29767f Mon Sep 17 00:00:00 2001 From: tdomy Date: Sat, 16 Jul 2022 18:43:41 +0900 Subject: [PATCH 75/83] Added abstract class to add return type --- src/Geometries/LineStringCollection.php | 68 +++++++++++++++++++++++++ src/Geometries/MultiLineString.php | 66 +----------------------- src/Geometries/Polygon.php | 10 +--- 3 files changed, 72 insertions(+), 72 deletions(-) create mode 100644 src/Geometries/LineStringCollection.php diff --git a/src/Geometries/LineStringCollection.php b/src/Geometries/LineStringCollection.php new file mode 100644 index 0000000..ff056c2 --- /dev/null +++ b/src/Geometries/LineStringCollection.php @@ -0,0 +1,68 @@ +linestrings = $linestrings; + } + + public function getLineStrings() + { + return $this->linestrings; + } + + public function is3d() + { + if (count($this->linestrings) === 0) return false; + return $this->linestrings[0]->is3d(); + } + + public static function fromString($wktArgument) + { + $str = preg_split('/\)\s*,\s*\(/', substr(trim($wktArgument), 1, -1)); + $linestrings = array_map(function ($data) { + return LineString::fromString($data); + }, $str); + + + return new static($linestrings); + } + + public function __toString() + { + return implode(',', array_map(function (LineString $linestring) { + return sprintf('(%s)', (string)$linestring); + }, $this->getLineStrings())); + } + + public function count(): int + { + return count($this->linestrings); + } +} diff --git a/src/Geometries/MultiLineString.php b/src/Geometries/MultiLineString.php index b3b82a7..090f695 100644 --- a/src/Geometries/MultiLineString.php +++ b/src/Geometries/MultiLineString.php @@ -2,47 +2,8 @@ namespace MStaack\LaravelPostgis\Geometries; -use Countable; -use InvalidArgumentException; - -class MultiLineString extends Geometry implements Countable +class MultiLineString extends LineStringCollection { - /** - * @var LineString[] - */ - protected $linestrings = []; - - /** - * @param LineString[] $linestrings - */ - public function __construct(array $linestrings) - { - if (count($linestrings) < 1) { - throw new InvalidArgumentException('$linestrings must contain at least one entry'); - } - - $validated = array_filter($linestrings, function ($value) { - return $value instanceof LineString; - }); - - if (count($linestrings) !== count($validated)) { - throw new InvalidArgumentException('$linestrings must be an array of Points'); - } - - $this->linestrings = $linestrings; - } - - public function getLineStrings() - { - return $this->linestrings; - } - - public function is3d() - { - if (count($this->linestrings) === 0) return false; - return $this->linestrings[0]->is3d(); - } - public function toWKT() { $wktType = 'MULTILINESTRING'; @@ -50,35 +11,12 @@ public function toWKT() return sprintf('%s(%s)', $wktType, (string)$this); } - public static function fromString($wktArgument) - { - $str = preg_split('/\)\s*,\s*\(/', substr(trim($wktArgument), 1, -1)); - $linestrings = array_map(function ($data) { - return LineString::fromString($data); - }, $str); - - - return new static($linestrings); - } - - public function __toString() - { - return implode(',', array_map(function (LineString $linestring) { - return sprintf('(%s)', (string)$linestring); - }, $this->getLineStrings())); - } - - public function count(): int - { - return count($this->linestrings); - } - /** * Convert to GeoJson Point that is jsonable to GeoJSON * * @return \GeoJson\Geometry\MultiLineString */ - public function jsonSerialize() + public function jsonSerialize(): \GeoJson\Geometry\MultiLineString { $linestrings = []; diff --git a/src/Geometries/Polygon.php b/src/Geometries/Polygon.php index edf1724..89ba6ff 100644 --- a/src/Geometries/Polygon.php +++ b/src/Geometries/Polygon.php @@ -4,14 +4,8 @@ use GeoJson\Geometry\LinearRing; -class Polygon extends MultiLineString +class Polygon extends LineStringCollection { - public function is3d() - { - if (count($this->linestrings) === 0) return false; - return $this->linestrings[0]->is3d(); - } - public function toWKT() { $wktType = 'POLYGON'; @@ -24,7 +18,7 @@ public function toWKT() * * @return \GeoJson\Geometry\Polygon */ - public function jsonSerialize() + public function jsonSerialize(): \GeoJson\Geometry\Polygon { $linearrings = []; foreach ($this->linestrings as $linestring) { From d450e36c10d9b96037d65e6f89ff6fa815eafc70 Mon Sep 17 00:00:00 2001 From: Max Date: Thu, 11 Aug 2022 11:48:56 +0200 Subject: [PATCH 76/83] fix default --- src/Geometries/Point.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Geometries/Point.php b/src/Geometries/Point.php index 1199447..4176d34 100644 --- a/src/Geometries/Point.php +++ b/src/Geometries/Point.php @@ -15,7 +15,7 @@ public function __construct($lat, $lng, $alt = null) $this->lng = (float)$lng; $this->alt = isset($alt) ? (float)$alt : null; $this->setPrecision( - function_exists('config') ? config('postgis.precision') : 6 + function_exists('config') ? config('postgis.precision', 6) : 6 ); } From f842b1d6a519ef218ab04e101ad9dfe8b78dd254 Mon Sep 17 00:00:00 2001 From: Max Date: Mon, 15 Aug 2022 13:34:46 +0200 Subject: [PATCH 77/83] Update run-tests.yml --- .github/workflows/run-tests.yml | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/.github/workflows/run-tests.yml b/.github/workflows/run-tests.yml index 0fa975f..b014e73 100644 --- a/.github/workflows/run-tests.yml +++ b/.github/workflows/run-tests.yml @@ -1,6 +1,7 @@ name: Test Suite -on: [push] +on: + push: jobs: tests: @@ -8,7 +9,7 @@ jobs: strategy: matrix: - php: [7.4, 7.3, 7.2] + php: [8.1 8.0 7.4] release: [stable, lowest] services: From 509adbaf003c6eeb512c92493ace70b83420e469 Mon Sep 17 00:00:00 2001 From: Max Date: Mon, 15 Aug 2022 13:38:50 +0200 Subject: [PATCH 78/83] fix build --- .github/workflows/run-tests.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/workflows/run-tests.yml b/.github/workflows/run-tests.yml index b014e73..f78dd13 100644 --- a/.github/workflows/run-tests.yml +++ b/.github/workflows/run-tests.yml @@ -2,6 +2,7 @@ name: Test Suite on: push: + pull_request: jobs: tests: @@ -29,7 +30,7 @@ jobs: with: path: ~/.composer/cache/files key: php-${{ matrix.php }}-composer-${{ hashFiles('**/composer.json') }} - - uses: shivammathur/setup-php@v1 + - uses: shivammathur/setup-php@v2 with: php-version: ${{ matrix.php }} tools: pecl From 2483bd8ce7a4f9c9c5cabd0ebb3f934faebc7e01 Mon Sep 17 00:00:00 2001 From: Max Date: Mon, 15 Aug 2022 13:41:16 +0200 Subject: [PATCH 79/83] fixup --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 5da9db1..7c43bba 100644 --- a/composer.json +++ b/composer.json @@ -10,7 +10,7 @@ }, "require-dev": { "illuminate/pagination": "^6.0|^7.0|^8.0|^9.0", - "phpunit/phpunit": "^8.5", + "phpunit/phpunit": ">=8.5.23", "mockery/mockery": "^1.3" }, "autoload": { From 801b129c51cf50353bd86ed1481365b018cefa43 Mon Sep 17 00:00:00 2001 From: Romain 'Maz' BILLOIR Date: Tue, 6 Dec 2022 12:22:45 +0100 Subject: [PATCH 80/83] Support upsert --- src/Eloquent/Builder.php | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/src/Eloquent/Builder.php b/src/Eloquent/Builder.php index 3c6f1b1..3f74ffe 100644 --- a/src/Eloquent/Builder.php +++ b/src/Eloquent/Builder.php @@ -21,6 +21,24 @@ public function update(array $values) return parent::update($values); } + public function upsert(array $values, $uniqueBy, $update = null) + { + foreach ($values as &$row) { + foreach ($row as $column => &$value) { + if ($value instanceof GeometryInterface) { + if (is_null($this->model)) { + $value = $this->asWKT($value); + } else { + $attrs = $this->model->getPostgisType($column); + $value = $this->model->asWKT($value, $attrs); + } + } + } + } + + return parent::upsert($values, $uniqueBy, $update); + } + protected function asWKT(GeometryInterface $geometry) { return $this->getQuery()->raw(sprintf("%s.ST_GeogFromText('%s')", From eddd7257b2de2c7a495d3d830c6c920e0be9b6c9 Mon Sep 17 00:00:00 2001 From: Shift Date: Wed, 1 Feb 2023 12:58:58 +0000 Subject: [PATCH 81/83] Bump dependencies for Laravel 10 --- composer.json | 92 +++++++++++++++++++++++++-------------------------- 1 file changed, 46 insertions(+), 46 deletions(-) diff --git a/composer.json b/composer.json index 7c43bba..c9785ed 100644 --- a/composer.json +++ b/composer.json @@ -1,51 +1,51 @@ { - "name": "mstaack/laravel-postgis", - "description": "Postgis extensions for laravel. Aims to make it easy to work with geometries from laravel models", - "require": { - "php": ">=7.1", - "illuminate/database": "^6.0|^7.0|^8.0|^9.0", - "geo-io/wkb-parser": "^1.0", - "jmikola/geojson": "^1.0", - "bosnadev/database": "^0.21|master" - }, - "require-dev": { - "illuminate/pagination": "^6.0|^7.0|^8.0|^9.0", - "phpunit/phpunit": ">=8.5.23", - "mockery/mockery": "^1.3" - }, - "autoload": { - "psr-4": { - "MStaack\\LaravelPostgis\\": "src/" - } - }, - "autoload-dev": { - "psr-4": { - "MStaack\\LaravelPostgis\\Tests\\": "tests/" - } - }, - "license": "MIT", - "authors": [ - { - "name": "Peter Haza", - "email": "peter.haza@gmail.com" + "name": "mstaack/laravel-postgis", + "description": "Postgis extensions for laravel. Aims to make it easy to work with geometries from laravel models", + "require": { + "php": ">=7.1", + "illuminate/database": "^6.0|^7.0|^8.0|^9.0|^10.0", + "geo-io/wkb-parser": "^1.0", + "jmikola/geojson": "^1.0", + "bosnadev/database": "^0.21|master" }, - { - "name": "Nicholas Barrett", - "email": "njbarrett7@gmail.com" + "require-dev": { + "illuminate/pagination": "^6.0|^7.0|^8.0|^9.0|^10.0", + "phpunit/phpunit": ">=8.5.23", + "mockery/mockery": "^1.3" }, - { - "name": "Max Matteo Staack", - "email": "maxmatteostaack@gmail.com" - } - ], - "extra": { - "laravel": { - "providers": [ - "MStaack\\LaravelPostgis\\DatabaseServiceProvider" - ] + "autoload": { + "psr-4": { + "MStaack\\LaravelPostgis\\": "src/" + } + }, + "autoload-dev": { + "psr-4": { + "MStaack\\LaravelPostgis\\Tests\\": "tests/" + } + }, + "license": "MIT", + "authors": [ + { + "name": "Peter Haza", + "email": "peter.haza@gmail.com" + }, + { + "name": "Nicholas Barrett", + "email": "njbarrett7@gmail.com" + }, + { + "name": "Max Matteo Staack", + "email": "maxmatteostaack@gmail.com" + } + ], + "extra": { + "laravel": { + "providers": [ + "MStaack\\LaravelPostgis\\DatabaseServiceProvider" + ] + } + }, + "scripts": { + "test": "./vendor/bin/phpunit" } - }, - "scripts": { - "test": "./vendor/bin/phpunit" - } } From 5065630e0cd5a244d642791cb99719508f7a549c Mon Sep 17 00:00:00 2001 From: Max Date: Tue, 28 Mar 2023 12:20:19 +0200 Subject: [PATCH 82/83] Update composer.json --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index c9785ed..b88bf2d 100644 --- a/composer.json +++ b/composer.json @@ -6,7 +6,7 @@ "illuminate/database": "^6.0|^7.0|^8.0|^9.0|^10.0", "geo-io/wkb-parser": "^1.0", "jmikola/geojson": "^1.0", - "bosnadev/database": "^0.21|master" + "bosnadev/database": "^0.21|dev-master" }, "require-dev": { "illuminate/pagination": "^6.0|^7.0|^8.0|^9.0|^10.0", From 8bd236a4673723aeb4e7d2689a5c3caaa044a028 Mon Sep 17 00:00:00 2001 From: Max Date: Wed, 10 Apr 2024 11:51:11 +0200 Subject: [PATCH 83/83] Update README.md --- README.md | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 9412f6c..4f9a8d3 100644 --- a/README.md +++ b/README.md @@ -3,6 +3,10 @@ Laravel Wrapper for PostgreSQL's Geo-Extension Postgis ![Build Status](https://github.com/mstaack/laravel-postgis/workflows/Test%20Suite/badge.svg) + +# DEPRECATED +Consider using: https://github.com/clickbar/laravel-magellan + ## Features * Work with geometry classes instead of arrays. @@ -251,4 +255,4 @@ return [ 'precision' => 6, ]; ``` -See http://wiki.gis.com/wiki/index.php/Decimal_degrees#Accuracy for more information \ No newline at end of file +See http://wiki.gis.com/wiki/index.php/Decimal_degrees#Accuracy for more information