Skip to content

Commit bfd98cb

Browse files
committed
Merge pull request creof#127 from djlambert/dev
Rename AbstractGeometryType to AbstractSpatialType, refactor abstract methods
2 parents 9f3986b + ff8ba57 commit bfd98cb

23 files changed

+102
-184
lines changed

CHANGELOG.md

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,12 @@ This project adheres to [Semantic Versioning](http://semver.org/).
66
### Added
77
- Added support for PostgreSql ST_MakeEnvelope function.
88
### Changed
9+
- Added implementation of getTypeFamily() and getSQLType() to AbstractGeometryType.
10+
- Rename AbstractGeometryType class to AbstractSpatialType.
11+
- Simplify logic in isClosed() method of AbstractLineString.
12+
- Updated copyright year in LICENSE.
913
### Removed
14+
- Unused imports from a number of classes.
1015

1116
## [1.1] - 2015-12-20
1217
### Added
@@ -77,5 +82,5 @@ This project adheres to [Semantic Versioning](http://semver.org/).
7782
- StringLexer and StringParser now correctly handle values with exponent/scientific notation.
7883

7984
### Removed
80-
- AbstractDualGeometryDQLFunction, AbstractDualGeometryOptionalParameterDQLFunction, AbstractGeometryDQLFunction, AbstractSingleGeometryDQLFunction, AbstractTripleGeometryDQLFunction, and AbstractVariableGeometryDQLFunction classes.
85+
- AbstractDualGeometryDQLFunction, AbstractDualGeometryOptionalParameterDQLFunction, AbstractGeometryDQLFunction, AbstractSingleGeometryDQLFunction, AbstractTripleGeometryDQLFunction, and AbstractVariableGeometryDQLFunction classes.
8186

LICENSE

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
Copyright (C) 2012, 2013, 2014 Derek J. Lambert
1+
Copyright (C) 2012-2015 Derek J. Lambert
22

33
Permission is hereby granted, free of charge, to any person obtaining a copy
44
of this software and associated documentation files (the "Software"), to deal

lib/CrEOF/Spatial/DBAL/Platform/AbstractPlatform.php

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525

2626
use CrEOF\Geo\WKT\Parser as StringParser;
2727
use CrEOF\Geo\WKB\Parser as BinaryParser;
28-
use CrEOF\Spatial\DBAL\Types\AbstractGeometryType;
28+
use CrEOF\Spatial\DBAL\Types\AbstractSpatialType;
2929
use CrEOF\Spatial\DBAL\Types\GeographyType;
3030
use CrEOF\Spatial\Exception\InvalidValueException;
3131
use CrEOF\Spatial\PHP\Types\Geometry\GeometryInterface;
@@ -39,50 +39,50 @@
3939
abstract class AbstractPlatform implements PlatformInterface
4040
{
4141
/**
42-
* @param AbstractGeometryType $type
43-
* @param string $sqlExpr
42+
* @param AbstractSpatialType $type
43+
* @param string $sqlExpr
4444
*
4545
* @return GeometryInterface
4646
*/
47-
public function convertStringToPHPValue(AbstractGeometryType $type, $sqlExpr)
47+
public function convertStringToPHPValue(AbstractSpatialType $type, $sqlExpr)
4848
{
4949
$parser = new StringParser($sqlExpr);
5050

5151
return $this->newObjectFromValue($type, $parser->parse());
5252
}
5353

5454
/**
55-
* @param AbstractGeometryType $type
56-
* @param string $sqlExpr
55+
* @param AbstractSpatialType $type
56+
* @param string $sqlExpr
5757
*
5858
* @return GeometryInterface
5959
*/
60-
public function convertBinaryToPHPValue(AbstractGeometryType $type, $sqlExpr)
60+
public function convertBinaryToPHPValue(AbstractSpatialType $type, $sqlExpr)
6161
{
6262
$parser = new BinaryParser($sqlExpr);
6363

6464
return $this->newObjectFromValue($type, $parser->parse());
6565
}
6666

6767
/**
68-
* @param AbstractGeometryType $type
69-
* @param GeometryInterface $value
68+
* @param AbstractSpatialType $type
69+
* @param GeometryInterface $value
7070
*
7171
* @return string
7272
*/
73-
public function convertToDatabaseValue(AbstractGeometryType $type, GeometryInterface $value)
73+
public function convertToDatabaseValue(AbstractSpatialType $type, GeometryInterface $value)
7474
{
7575
return sprintf('%s(%s)', strtoupper($value->getType()), $value);
7676
}
7777

7878
/**
7979
* Get an array of database types that map to this Doctrine type.
8080
*
81-
* @param AbstractGeometryType $type
81+
* @param AbstractSpatialType $type
8282
*
8383
* @return string[]
8484
*/
85-
public function getMappedDatabaseTypes(AbstractGeometryType $type)
85+
public function getMappedDatabaseTypes(AbstractSpatialType $type)
8686
{
8787
$sqlType = strtolower($type->getSQLType());
8888

@@ -96,13 +96,13 @@ public function getMappedDatabaseTypes(AbstractGeometryType $type)
9696
/**
9797
* Create spatial object from parsed value
9898
*
99-
* @param AbstractGeometryType $type
100-
* @param array $value
99+
* @param AbstractSpatialType $type
100+
* @param array $value
101101
*
102102
* @return GeometryInterface
103103
* @throws \CrEOF\Spatial\Exception\InvalidValueException
104104
*/
105-
private function newObjectFromValue(AbstractGeometryType $type, $value)
105+
private function newObjectFromValue(AbstractSpatialType $type, $value)
106106
{
107107
$typeFamily = $type->getTypeFamily();
108108
$typeName = strtoupper($value['type']);

lib/CrEOF/Spatial/DBAL/Platform/MySql.php

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323

2424
namespace CrEOF\Spatial\DBAL\Platform;
2525

26-
use CrEOF\Spatial\DBAL\Types\AbstractGeometryType;
26+
use CrEOF\Spatial\DBAL\Types\AbstractSpatialType;
2727
use CrEOF\Spatial\PHP\Types\Geography\GeographyInterface;
2828

2929
/**
@@ -51,23 +51,23 @@ public function getSQLDeclaration(array $fieldDeclaration)
5151
}
5252

5353
/**
54-
* @param AbstractGeometryType $type
55-
* @param string $sqlExpr
54+
* @param AbstractSpatialType $type
55+
* @param string $sqlExpr
5656
*
5757
* @return string
5858
*/
59-
public function convertToPHPValueSQL(AbstractGeometryType $type, $sqlExpr)
59+
public function convertToPHPValueSQL(AbstractSpatialType $type, $sqlExpr)
6060
{
6161
return sprintf('AsBinary(%s)', $sqlExpr);
6262
}
6363

6464
/**
65-
* @param AbstractGeometryType $type
66-
* @param string $sqlExpr
65+
* @param AbstractSpatialType $type
66+
* @param string $sqlExpr
6767
*
6868
* @return string
6969
*/
70-
public function convertToDatabaseValueSQL(AbstractGeometryType $type, $sqlExpr)
70+
public function convertToDatabaseValueSQL(AbstractSpatialType $type, $sqlExpr)
7171
{
7272
return sprintf('GeomFromText(%s)', $sqlExpr);
7373
}

lib/CrEOF/Spatial/DBAL/Platform/PlatformInterface.php

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323

2424
namespace CrEOF\Spatial\DBAL\Platform;
2525

26-
use CrEOF\Spatial\DBAL\Types\AbstractGeometryType;
26+
use CrEOF\Spatial\DBAL\Types\AbstractSpatialType;
2727
use CrEOF\Spatial\PHP\Types\Geometry\GeometryInterface;
2828

2929
/**
@@ -35,44 +35,44 @@
3535
interface PlatformInterface
3636
{
3737
/**
38-
* @param AbstractGeometryType $type
39-
* @param string $sqlExpr
38+
* @param AbstractSpatialType $type
39+
* @param string $sqlExpr
4040
*
4141
* @return GeometryInterface
4242
*/
43-
public function convertBinaryToPHPValue(AbstractGeometryType $type, $sqlExpr);
43+
public function convertBinaryToPHPValue(AbstractSpatialType $type, $sqlExpr);
4444

4545
/**
46-
* @param AbstractGeometryType $type
47-
* @param string $sqlExpr
46+
* @param AbstractSpatialType $type
47+
* @param string $sqlExpr
4848
*
4949
* @return GeometryInterface
5050
*/
51-
public function convertStringToPHPValue(AbstractGeometryType $type, $sqlExpr);
51+
public function convertStringToPHPValue(AbstractSpatialType $type, $sqlExpr);
5252

5353
/**
54-
* @param AbstractGeometryType $type
55-
* @param GeometryInterface $value
54+
* @param AbstractSpatialType $type
55+
* @param GeometryInterface $value
5656
*
5757
* @return string
5858
*/
59-
public function convertToDatabaseValue(AbstractGeometryType $type, GeometryInterface $value);
59+
public function convertToDatabaseValue(AbstractSpatialType $type, GeometryInterface $value);
6060

6161
/**
62-
* @param AbstractGeometryType $type
63-
* @param string $sqlExpr
62+
* @param AbstractSpatialType $type
63+
* @param string $sqlExpr
6464
*
6565
* @return string
6666
*/
67-
public function convertToDatabaseValueSQL(AbstractGeometryType $type, $sqlExpr);
67+
public function convertToDatabaseValueSQL(AbstractSpatialType $type, $sqlExpr);
6868

6969
/**
70-
* @param AbstractGeometryType $type
71-
* @param string $sqlExpr
70+
* @param AbstractSpatialType $type
71+
* @param string $sqlExpr
7272
*
7373
* @return string
7474
*/
75-
public function convertToPHPValueSQL(AbstractGeometryType $type, $sqlExpr);
75+
public function convertToPHPValueSQL(AbstractSpatialType $type, $sqlExpr);
7676

7777
/**
7878
* Gets the SQL declaration snippet for a field of this type.
@@ -84,9 +84,9 @@ public function convertToPHPValueSQL(AbstractGeometryType $type, $sqlExpr);
8484
public function getSQLDeclaration(array $fieldDeclaration);
8585

8686
/**
87-
* @param AbstractGeometryType $type
87+
* @param AbstractSpatialType $type
8888
*
8989
* @return string[]
9090
*/
91-
public function getMappedDatabaseTypes(AbstractGeometryType $type);
91+
public function getMappedDatabaseTypes(AbstractSpatialType $type);
9292
}

lib/CrEOF/Spatial/DBAL/Platform/PostgreSql.php

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323

2424
namespace CrEOF\Spatial\DBAL\Platform;
2525

26-
use CrEOF\Spatial\DBAL\Types\AbstractGeometryType;
26+
use CrEOF\Spatial\DBAL\Types\AbstractSpatialType;
2727
use CrEOF\Spatial\DBAL\Types\GeographyType;
2828
use CrEOF\Spatial\Exception\InvalidValueException;
2929
use CrEOF\Spatial\PHP\Types\Geometry\GeometryInterface;
@@ -62,12 +62,12 @@ public function getSQLDeclaration(array $fieldDeclaration)
6262
}
6363

6464
/**
65-
* @param AbstractGeometryType $type
66-
* @param string $sqlExpr
65+
* @param AbstractSpatialType $type
66+
* @param string $sqlExpr
6767
*
6868
* @return string
6969
*/
70-
public function convertToPHPValueSQL(AbstractGeometryType $type, $sqlExpr)
70+
public function convertToPHPValueSQL(AbstractSpatialType $type, $sqlExpr)
7171
{
7272
if ($type instanceof GeographyType) {
7373
return sprintf('ST_AsEWKT(%s)', $sqlExpr);
@@ -77,12 +77,12 @@ public function convertToPHPValueSQL(AbstractGeometryType $type, $sqlExpr)
7777
}
7878

7979
/**
80-
* @param AbstractGeometryType $type
81-
* @param string $sqlExpr
80+
* @param AbstractSpatialType $type
81+
* @param string $sqlExpr
8282
*
8383
* @return string
8484
*/
85-
public function convertToDatabaseValueSQL(AbstractGeometryType $type, $sqlExpr)
85+
public function convertToDatabaseValueSQL(AbstractSpatialType $type, $sqlExpr)
8686
{
8787
if ($type instanceof GeographyType) {
8888
return sprintf('ST_GeographyFromText(%s)', $sqlExpr);
@@ -92,13 +92,13 @@ public function convertToDatabaseValueSQL(AbstractGeometryType $type, $sqlExpr)
9292
}
9393

9494
/**
95-
* @param AbstractGeometryType $type
96-
* @param string $sqlExpr
95+
* @param AbstractSpatialType $type
96+
* @param string $sqlExpr
9797
*
9898
* @return GeometryInterface
9999
* @throws InvalidValueException
100100
*/
101-
public function convertBinaryToPHPValue(AbstractGeometryType $type, $sqlExpr)
101+
public function convertBinaryToPHPValue(AbstractSpatialType $type, $sqlExpr)
102102
{
103103
if (! is_resource($sqlExpr)) {
104104
throw new InvalidValueException(sprintf('Invalid resource value "%s"', $sqlExpr));
@@ -110,12 +110,12 @@ public function convertBinaryToPHPValue(AbstractGeometryType $type, $sqlExpr)
110110
}
111111

112112
/**
113-
* @param AbstractGeometryType $type
114-
* @param GeometryInterface $value
113+
* @param AbstractSpatialType $type
114+
* @param GeometryInterface $value
115115
*
116116
* @return string
117117
*/
118-
public function convertToDatabaseValue(AbstractGeometryType $type, GeometryInterface $value)
118+
public function convertToDatabaseValue(AbstractSpatialType $type, GeometryInterface $value)
119119
{
120120
$sridSQL = null;
121121

lib/CrEOF/Spatial/DBAL/Types/AbstractGeometryType.php renamed to lib/CrEOF/Spatial/DBAL/Types/AbstractSpatialType.php

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
use CrEOF\Spatial\Exception\InvalidValueException;
2727
use CrEOF\Spatial\Exception\UnsupportedPlatformException;
2828
use CrEOF\Spatial\DBAL\Platform\PlatformInterface;
29+
use CrEOF\Spatial\PHP\Types\Geography\GeographyInterface;
2930
use CrEOF\Spatial\PHP\Types\Geometry\GeometryInterface;
3031
use Doctrine\DBAL\Platforms\AbstractPlatform;
3132
use Doctrine\DBAL\Types\Type;
@@ -36,22 +37,32 @@
3637
* @author Derek J. Lambert <dlambert@dereklambert.com>
3738
* @license http://dlambert.mit-license.org MIT
3839
*/
39-
abstract class AbstractGeometryType extends Type
40+
abstract class AbstractSpatialType extends Type
4041
{
4142
const PLATFORM_MYSQL = 'MySql';
4243
const PLATFORM_POSTGRESQL = 'PostgreSql';
4344

4445
/**
4546
* @return string
4647
*/
47-
abstract public function getTypeFamily();
48+
public function getTypeFamily()
49+
{
50+
return $this instanceof GeographyType ? GeographyInterface::GEOGRAPHY : GeometryInterface::GEOMETRY;
51+
}
4852

4953
/**
5054
* Gets the SQL name of this type.
5155
*
5256
* @return string
5357
*/
54-
abstract public function getSQLType();
58+
public function getSQLType()
59+
{
60+
$class = get_class($this);
61+
$start = strrpos($class, '\\') + 1;
62+
$len = strlen($class) - $start - 4;
63+
64+
return substr($class, strrpos($class, '\\') + 1, $len);
65+
}
5566

5667
/**
5768
* @return bool
@@ -138,7 +149,7 @@ public function convertToPHPValue($value, AbstractPlatform $platform)
138149
*/
139150
public function getName()
140151
{
141-
return array_search(get_class($this), $this->getTypesMap());
152+
return array_search(get_class($this), self::getTypesMap(), true);
142153
}
143154

144155
/**

lib/CrEOF/Spatial/DBAL/Types/Geography/LineStringType.php

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?php
22
/**
3-
* Copyright (C) 2012 Derek J. Lambert
3+
* Copyright (C) 2015 Derek J. Lambert
44
*
55
* Permission is hereby granted, free of charge, to any person obtaining a copy
66
* of this software and associated documentation files (the "Software"), to deal
@@ -24,7 +24,6 @@
2424
namespace CrEOF\Spatial\DBAL\Types\Geography;
2525

2626
use CrEOF\Spatial\DBAL\Types\GeographyType;
27-
use CrEOF\Spatial\PHP\Types\Geometry\GeometryInterface;
2827

2928
/**
3029
* Doctrine LINESTRING type
@@ -34,11 +33,5 @@
3433
*/
3534
class LineStringType extends GeographyType
3635
{
37-
/**
38-
* {@inheritdoc}
39-
*/
40-
public function getSQLType()
41-
{
42-
return GeometryInterface::LINESTRING;
43-
}
36+
4437
}

0 commit comments

Comments
 (0)