Skip to content

Commit

Permalink
Refactor Classes
Browse files Browse the repository at this point in the history
  • Loading branch information
atsanna committed Jun 19, 2022
1 parent dd3e590 commit 8bf1193
Show file tree
Hide file tree
Showing 8 changed files with 124 additions and 10 deletions.
8 changes: 3 additions & 5 deletions src/SpatialPostgre/Forge.php → src/Geometry/Geometry.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,11 @@
* the LICENSE file that was distributed with this source code.
*/

namespace atsanna\Spatial\SpatialPostgre;

use CodeIgniter\Database\Postgre\Forge as BaseForge;
namespace atsanna\Spatial\Geometry;

/**
* Forge for Postgre
* Geometry abstract class
*/
class Forge extends BaseForge
abstract class Geometry
{
}
20 changes: 20 additions & 0 deletions src/Geometry/Point.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?php

/**
* This file is part of Spatial.
*
* (c) Antonio Sanna <atsanna@tiscali.it>
*
* For the full copyright and license information, please view
* the LICENSE file that was distributed with this source code.
*/

namespace atsanna\Spatial\Geometry;

/**
* Point: The most basic geometry type. All other geometries
* are built out of Points.
*/
class Point extends Geometry
{
}
2 changes: 1 addition & 1 deletion src/SpatialPostgre/Builder.php → src/Postgre/Builder.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
* the LICENSE file that was distributed with this source code.
*/

namespace atsanna\Spatial\SpatialPostgre;
namespace atsanna\Spatial\Postgre;

use CodeIgniter\Database\Postgre\Builder as BaseBuilder;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
* the LICENSE file that was distributed with this source code.
*/

namespace atsanna\Spatial\SpatialPostgre;
namespace atsanna\Spatial\Postgre;

use CodeIgniter\Database\Postgre\Connection as BaseConnection;

Expand Down
96 changes: 96 additions & 0 deletions src/Postgre/Forge.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
<?php

/**
* This file is part of Spatial.
*
* (c) Antonio Sanna <atsanna@tiscali.it>
*
* For the full copyright and license information, please view
* the LICENSE file that was distributed with this source code.
*/

namespace atsanna\Spatial\Postgre;

use CodeIgniter\Database\Postgre\Forge as BaseForge;

/**
* Forge for Postgre
*/
class Forge extends BaseForge
{
/**
* Create the postgis extension
*
* @var string
*/
protected $createPostisExtensionStr = 'CREATE EXTENSION postgis';

/**
* Create the postgis extension, if it doesn't already exist statement
*
* @var string
*/
protected $createPostisExtensionIfNotExistStr = 'CREATE CREATE EXTENSION IF NOT EXISTS postgis';

/**
* Drop the postgis extension
*
* @var string
*/
protected $dropPostisExtensionStr = 'DROP EXTENSION postgis';

/**
* Drop the postgis extension, if it exists
*
* @var string
*/
protected $dropPostisExtensionIfExistStr = 'DROP EXTENSION IF EXISTS postgis';

/**
* Allowed geometry type
*
* @var array
*/
protected $allowed_geom_types = ['GEOGRAPHY', 'GEOMETRY'];

/**
* Column type
*
* @var array
*/
protected $columnType = [
'POINT',
'POINTZ',
'MULTIPOINT',
'POLYGON',
'MULTIPOLYGON',
'MULTIPOLYGONZ',
'LINESTRING',
'LINESTRINGZ',
'MULTILINESTRING',
];

/**
* Add Geometry Field
*
* @param string $field
* @param string $type
* @param int $srID
*
* @return Forge
*/
public function addGeometryField($field = 'the_geom', $type = 'POINT', $srID = 4326)
{
$type = strtoupper($type);

if (is_string($field) && in_array($type, $this->columnType, true)) {
$this->addField([
$field => [
'type' => 'geometry(' . $type . ',' . $srID . ')',
],
]);
}

return $this;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
* the LICENSE file that was distributed with this source code.
*/

namespace atsanna\Spatial\SpatialPostgre;
namespace atsanna\Spatial\Postgre;

use CodeIgniter\Database\Postgre\PreparedQuery as BasePreparedQuery;

Expand Down
2 changes: 1 addition & 1 deletion src/SpatialPostgre/Result.php → src/Postgre/Result.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
* the LICENSE file that was distributed with this source code.
*/

namespace atsanna\Spatial\SpatialPostgre;
namespace atsanna\Spatial\Postgre;

use CodeIgniter\Database\Postgre\Result as BaseResult;

Expand Down
2 changes: 1 addition & 1 deletion src/SpatialPostgre/Utils.php → src/Postgre/Utils.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
* the LICENSE file that was distributed with this source code.
*/

namespace atsanna\Spatial\SpatialPostgre;
namespace atsanna\Spatial\Postgre;

use CodeIgniter\Database\Postgre\Utils as BaseUtils;

Expand Down

0 comments on commit 8bf1193

Please sign in to comment.