This repository has been archived by the owner on Jun 28, 2021. It is now read-only.
forked from creof/doctrine2-spatial
-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Geometry and Geography implements JsonSerializable
- Loading branch information
1 parent
55bef51
commit 21e6e85
Showing
8 changed files
with
75 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -26,14 +26,15 @@ | |
|
||
use CrEOF\Spatial\Exception\InvalidValueException; | ||
use CrEOF\Spatial\PHP\Types\Geometry\GeometryInterface; | ||
use JsonSerializable; | ||
|
||
/** | ||
* Abstract geometry object for spatial types. | ||
* | ||
* @author Derek J. Lambert <[email protected]> | ||
* @license https://dlambert.mit-license.org MIT | ||
*/ | ||
abstract class AbstractGeometry implements GeometryInterface | ||
abstract class AbstractGeometry implements GeometryInterface, JsonSerializable | ||
{ | ||
/** | ||
* Spatial Reference System Identifier. | ||
|
@@ -52,6 +53,26 @@ public function getSrid() | |
return $this->srid; | ||
} | ||
|
||
/** | ||
* Specify data which should be serialized to JSON. | ||
* | ||
* @see https://php.net/manual/en/jsonserializable.jsonserialize.php | ||
* @see https://github.com/creof/doctrine2-spatial/issues/140 | ||
* | ||
* @return mixed data which can be serialized by <b>json_encode</b>, | ||
* which is a value of any type other than a resource | ||
* | ||
* @since 2.0.0.rc-1 | ||
*/ | ||
public function jsonSerialize() | ||
{ | ||
return [ | ||
'type' => $this->getType(), | ||
'coordinates' => $this->toArray(), | ||
'srid' => $this->getSrid(), | ||
]; | ||
} | ||
|
||
/** | ||
* Spatial Reference System Identifier fluent setter. | ||
* | ||
|
@@ -85,6 +106,7 @@ public function toJson() | |
$json = []; | ||
$json['type'] = $this->getType(); | ||
$json['coordinates'] = $this->toArray(); | ||
$json['srid'] = $this->getSrid(); | ||
|
||
return json_encode($json); | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters