Skip to content
This repository was archived by the owner on May 3, 2024. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
80 changes: 80 additions & 0 deletions src/GeoJSON.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
<?php
/**
* Copyright 2014-2017 Aerospike, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* @category Database
* @package Aerospike
* @subpackage GeoJSON
* @author Ronen Botzer <[email protected]>
* @copyright Copyright 2014-2017 Aerospike, Inc.
* @license http://www.apache.org/licenses/LICENSE-2.0 Apache License, Version 2
* @filesource
*/

namespace Aerospike;

class GeoJSON implements \Aerospike\GeoJSON\Serializable
{
protected $type;
protected $coordinates;

public function __construct($geo) {
$this->type = $geo->type;
$this->coordinates = $geo->coordinates;
}

public function getType() {
return $this->type;
}

public function __toString() {
$arr = array('type'=> $this->type, 'coordinates' => $this->coordinates);
return json_encode($arr);
}

public function jsonSerialize() {
$geo_obj = new \stdClass();
$geo_obj->type = $this->type;
$geo_obj->coordinates = $this->coordinates;
return $geo_obj;
}

public function toObject() {
$geo_obj = new \stdClass();
$geo_obj->type = $this->type;
$geo_obj->coordinates = $this->coordinates;
return $geo_obj;
}

public function toArray() {
return array('type'=> $this->type, 'coordinates' => $this->coordinates);
}

public static function fromArray($geo_array) {
$geo_obj = new \stdClass();
$geo_obj->type = $geo_array["type"];
$geo_obj->coordinates = $geo_array["coordinates"];
return new \Aerospike\GeoJSON($geo_obj);
}

public static function fromJson($geo_json) {
$geo = json_decode($geo_json);
$geo_obj = new \stdClass();
$geo_obj->type = $geo->type;;
$geo_obj->coordinates = $geo->coordinates;
return new \Aerospike\GeoJSON($geo_obj);
}
}

9 changes: 4 additions & 5 deletions src/GeoJSON/Autoloader.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,10 @@ public static function load($class_name)
$parts = explode('\\', $class_name);

if ($parts[0] == "Aerospike" && $parts[1] == "GeoJSON") {
if (count($parts) == 2) {
require __DIR__. DIRECTORY_SEPARATOR. 'GeoJSON.php';
}
elseif ($parts[2] == 'Serializable') {
require __DIR__. DIRECTORY_SEPARATOR. 'Serializable.php';
if (count($parts) == 2) {
require __DIR__ . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . 'GeoJSON.php';
} elseif ($parts[2] == 'Serializable') {
require __DIR__ . DIRECTORY_SEPARATOR . 'Serializable.php';
}
}
}
Expand Down
79 changes: 1 addition & 78 deletions src/GeoJSON/GeoJSON.php
Original file line number Diff line number Diff line change
@@ -1,80 +1,3 @@
<?php
/**
* Copyright 2014-2017 Aerospike, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* @category Database
* @package Aerospike
* @subpackage GeoJSON
* @author Ronen Botzer <[email protected]>
* @copyright Copyright 2014-2017 Aerospike, Inc.
* @license http://www.apache.org/licenses/LICENSE-2.0 Apache License, Version 2
* @filesource
*/

namespace Aerospike;

class GeoJSON implements \Aerospike\GeoJSON\Serializable
{
protected $type;
protected $coordinates;

public function __construct($geo) {
$this->type = $geo->type;
$this->coordinates = $geo->coordinates;
}

public function getType() {
return $this->type;
}

public function __toString() {
$arr = array('type'=> $this->type, 'coordinates' => $this->coordinates);
return json_encode($arr);
}

public function jsonSerialize() {
$geo_obj = new \stdClass();
$geo_obj->type = $this->type;
$geo_obj->coordinates = $this->coordinates;
return $geo_obj;
}

public function toObject() {
$geo_obj = new \stdClass();
$geo_obj->type = $this->type;
$geo_obj->coordinates = $this->coordinates;
return $geo_obj;
}

public function toArray() {
return array('type'=> $this->type, 'coordinates' => $this->coordinates);
}

public static function fromArray($geo_array) {
$geo_obj = new \stdClass();
$geo_obj->type = $geo_array["type"];
$geo_obj->coordinates = $geo_array["coordinates"];
return new \Aerospike\GeoJSON($geo_obj);
}

public static function fromJson($geo_json) {
$geo = json_decode($geo_json);
$geo_obj = new \stdClass();
$geo_obj->type = $geo->type;;
$geo_obj->coordinates = $geo->coordinates;
return new \Aerospike\GeoJSON($geo_obj);
}
}

require_once __DIR__ . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . 'GeoJSON.php';