Skip to content

Commit

Permalink
Merge pull request creof#127 from djlambert/dev
Browse files Browse the repository at this point in the history
Rename AbstractGeometryType to AbstractSpatialType, refactor abstract methods
  • Loading branch information
sadortun committed Dec 27, 2015
2 parents 9f3986b + ff8ba57 commit bfd98cb
Show file tree
Hide file tree
Showing 23 changed files with 102 additions and 184 deletions.
7 changes: 6 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,12 @@ This project adheres to [Semantic Versioning](http://semver.org/).
### Added
- Added support for PostgreSql ST_MakeEnvelope function.
### Changed
- Added implementation of getTypeFamily() and getSQLType() to AbstractGeometryType.
- Rename AbstractGeometryType class to AbstractSpatialType.
- Simplify logic in isClosed() method of AbstractLineString.
- Updated copyright year in LICENSE.
### Removed
- Unused imports from a number of classes.

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

### Removed
- AbstractDualGeometryDQLFunction, AbstractDualGeometryOptionalParameterDQLFunction, AbstractGeometryDQLFunction, AbstractSingleGeometryDQLFunction, AbstractTripleGeometryDQLFunction, and AbstractVariableGeometryDQLFunction classes.
- AbstractDualGeometryDQLFunction, AbstractDualGeometryOptionalParameterDQLFunction, AbstractGeometryDQLFunction, AbstractSingleGeometryDQLFunction, AbstractTripleGeometryDQLFunction, and AbstractVariableGeometryDQLFunction classes.

2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Copyright (C) 2012, 2013, 2014 Derek J. Lambert
Copyright (C) 2012-2015 Derek J. Lambert

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
30 changes: 15 additions & 15 deletions lib/CrEOF/Spatial/DBAL/Platform/AbstractPlatform.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@

use CrEOF\Geo\WKT\Parser as StringParser;
use CrEOF\Geo\WKB\Parser as BinaryParser;
use CrEOF\Spatial\DBAL\Types\AbstractGeometryType;
use CrEOF\Spatial\DBAL\Types\AbstractSpatialType;
use CrEOF\Spatial\DBAL\Types\GeographyType;
use CrEOF\Spatial\Exception\InvalidValueException;
use CrEOF\Spatial\PHP\Types\Geometry\GeometryInterface;
Expand All @@ -39,50 +39,50 @@
abstract class AbstractPlatform implements PlatformInterface
{
/**
* @param AbstractGeometryType $type
* @param string $sqlExpr
* @param AbstractSpatialType $type
* @param string $sqlExpr
*
* @return GeometryInterface
*/
public function convertStringToPHPValue(AbstractGeometryType $type, $sqlExpr)
public function convertStringToPHPValue(AbstractSpatialType $type, $sqlExpr)
{
$parser = new StringParser($sqlExpr);

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

/**
* @param AbstractGeometryType $type
* @param string $sqlExpr
* @param AbstractSpatialType $type
* @param string $sqlExpr
*
* @return GeometryInterface
*/
public function convertBinaryToPHPValue(AbstractGeometryType $type, $sqlExpr)
public function convertBinaryToPHPValue(AbstractSpatialType $type, $sqlExpr)
{
$parser = new BinaryParser($sqlExpr);

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

/**
* @param AbstractGeometryType $type
* @param GeometryInterface $value
* @param AbstractSpatialType $type
* @param GeometryInterface $value
*
* @return string
*/
public function convertToDatabaseValue(AbstractGeometryType $type, GeometryInterface $value)
public function convertToDatabaseValue(AbstractSpatialType $type, GeometryInterface $value)
{
return sprintf('%s(%s)', strtoupper($value->getType()), $value);
}

/**
* Get an array of database types that map to this Doctrine type.
*
* @param AbstractGeometryType $type
* @param AbstractSpatialType $type
*
* @return string[]
*/
public function getMappedDatabaseTypes(AbstractGeometryType $type)
public function getMappedDatabaseTypes(AbstractSpatialType $type)
{
$sqlType = strtolower($type->getSQLType());

Expand All @@ -96,13 +96,13 @@ public function getMappedDatabaseTypes(AbstractGeometryType $type)
/**
* Create spatial object from parsed value
*
* @param AbstractGeometryType $type
* @param array $value
* @param AbstractSpatialType $type
* @param array $value
*
* @return GeometryInterface
* @throws \CrEOF\Spatial\Exception\InvalidValueException
*/
private function newObjectFromValue(AbstractGeometryType $type, $value)
private function newObjectFromValue(AbstractSpatialType $type, $value)
{
$typeFamily = $type->getTypeFamily();
$typeName = strtoupper($value['type']);
Expand Down
14 changes: 7 additions & 7 deletions lib/CrEOF/Spatial/DBAL/Platform/MySql.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@

namespace CrEOF\Spatial\DBAL\Platform;

use CrEOF\Spatial\DBAL\Types\AbstractGeometryType;
use CrEOF\Spatial\DBAL\Types\AbstractSpatialType;
use CrEOF\Spatial\PHP\Types\Geography\GeographyInterface;

/**
Expand Down Expand Up @@ -51,23 +51,23 @@ public function getSQLDeclaration(array $fieldDeclaration)
}

/**
* @param AbstractGeometryType $type
* @param string $sqlExpr
* @param AbstractSpatialType $type
* @param string $sqlExpr
*
* @return string
*/
public function convertToPHPValueSQL(AbstractGeometryType $type, $sqlExpr)
public function convertToPHPValueSQL(AbstractSpatialType $type, $sqlExpr)
{
return sprintf('AsBinary(%s)', $sqlExpr);
}

/**
* @param AbstractGeometryType $type
* @param string $sqlExpr
* @param AbstractSpatialType $type
* @param string $sqlExpr
*
* @return string
*/
public function convertToDatabaseValueSQL(AbstractGeometryType $type, $sqlExpr)
public function convertToDatabaseValueSQL(AbstractSpatialType $type, $sqlExpr)
{
return sprintf('GeomFromText(%s)', $sqlExpr);
}
Expand Down
36 changes: 18 additions & 18 deletions lib/CrEOF/Spatial/DBAL/Platform/PlatformInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@

namespace CrEOF\Spatial\DBAL\Platform;

use CrEOF\Spatial\DBAL\Types\AbstractGeometryType;
use CrEOF\Spatial\DBAL\Types\AbstractSpatialType;
use CrEOF\Spatial\PHP\Types\Geometry\GeometryInterface;

/**
Expand All @@ -35,44 +35,44 @@
interface PlatformInterface
{
/**
* @param AbstractGeometryType $type
* @param string $sqlExpr
* @param AbstractSpatialType $type
* @param string $sqlExpr
*
* @return GeometryInterface
*/
public function convertBinaryToPHPValue(AbstractGeometryType $type, $sqlExpr);
public function convertBinaryToPHPValue(AbstractSpatialType $type, $sqlExpr);

/**
* @param AbstractGeometryType $type
* @param string $sqlExpr
* @param AbstractSpatialType $type
* @param string $sqlExpr
*
* @return GeometryInterface
*/
public function convertStringToPHPValue(AbstractGeometryType $type, $sqlExpr);
public function convertStringToPHPValue(AbstractSpatialType $type, $sqlExpr);

/**
* @param AbstractGeometryType $type
* @param GeometryInterface $value
* @param AbstractSpatialType $type
* @param GeometryInterface $value
*
* @return string
*/
public function convertToDatabaseValue(AbstractGeometryType $type, GeometryInterface $value);
public function convertToDatabaseValue(AbstractSpatialType $type, GeometryInterface $value);

/**
* @param AbstractGeometryType $type
* @param string $sqlExpr
* @param AbstractSpatialType $type
* @param string $sqlExpr
*
* @return string
*/
public function convertToDatabaseValueSQL(AbstractGeometryType $type, $sqlExpr);
public function convertToDatabaseValueSQL(AbstractSpatialType $type, $sqlExpr);

/**
* @param AbstractGeometryType $type
* @param string $sqlExpr
* @param AbstractSpatialType $type
* @param string $sqlExpr
*
* @return string
*/
public function convertToPHPValueSQL(AbstractGeometryType $type, $sqlExpr);
public function convertToPHPValueSQL(AbstractSpatialType $type, $sqlExpr);

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

/**
* @param AbstractGeometryType $type
* @param AbstractSpatialType $type
*
* @return string[]
*/
public function getMappedDatabaseTypes(AbstractGeometryType $type);
public function getMappedDatabaseTypes(AbstractSpatialType $type);
}
26 changes: 13 additions & 13 deletions lib/CrEOF/Spatial/DBAL/Platform/PostgreSql.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@

namespace CrEOF\Spatial\DBAL\Platform;

use CrEOF\Spatial\DBAL\Types\AbstractGeometryType;
use CrEOF\Spatial\DBAL\Types\AbstractSpatialType;
use CrEOF\Spatial\DBAL\Types\GeographyType;
use CrEOF\Spatial\Exception\InvalidValueException;
use CrEOF\Spatial\PHP\Types\Geometry\GeometryInterface;
Expand Down Expand Up @@ -62,12 +62,12 @@ public function getSQLDeclaration(array $fieldDeclaration)
}

/**
* @param AbstractGeometryType $type
* @param string $sqlExpr
* @param AbstractSpatialType $type
* @param string $sqlExpr
*
* @return string
*/
public function convertToPHPValueSQL(AbstractGeometryType $type, $sqlExpr)
public function convertToPHPValueSQL(AbstractSpatialType $type, $sqlExpr)
{
if ($type instanceof GeographyType) {
return sprintf('ST_AsEWKT(%s)', $sqlExpr);
Expand All @@ -77,12 +77,12 @@ public function convertToPHPValueSQL(AbstractGeometryType $type, $sqlExpr)
}

/**
* @param AbstractGeometryType $type
* @param string $sqlExpr
* @param AbstractSpatialType $type
* @param string $sqlExpr
*
* @return string
*/
public function convertToDatabaseValueSQL(AbstractGeometryType $type, $sqlExpr)
public function convertToDatabaseValueSQL(AbstractSpatialType $type, $sqlExpr)
{
if ($type instanceof GeographyType) {
return sprintf('ST_GeographyFromText(%s)', $sqlExpr);
Expand All @@ -92,13 +92,13 @@ public function convertToDatabaseValueSQL(AbstractGeometryType $type, $sqlExpr)
}

/**
* @param AbstractGeometryType $type
* @param string $sqlExpr
* @param AbstractSpatialType $type
* @param string $sqlExpr
*
* @return GeometryInterface
* @throws InvalidValueException
*/
public function convertBinaryToPHPValue(AbstractGeometryType $type, $sqlExpr)
public function convertBinaryToPHPValue(AbstractSpatialType $type, $sqlExpr)
{
if (! is_resource($sqlExpr)) {
throw new InvalidValueException(sprintf('Invalid resource value "%s"', $sqlExpr));
Expand All @@ -110,12 +110,12 @@ public function convertBinaryToPHPValue(AbstractGeometryType $type, $sqlExpr)
}

/**
* @param AbstractGeometryType $type
* @param GeometryInterface $value
* @param AbstractSpatialType $type
* @param GeometryInterface $value
*
* @return string
*/
public function convertToDatabaseValue(AbstractGeometryType $type, GeometryInterface $value)
public function convertToDatabaseValue(AbstractSpatialType $type, GeometryInterface $value)
{
$sridSQL = null;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
use CrEOF\Spatial\Exception\InvalidValueException;
use CrEOF\Spatial\Exception\UnsupportedPlatformException;
use CrEOF\Spatial\DBAL\Platform\PlatformInterface;
use CrEOF\Spatial\PHP\Types\Geography\GeographyInterface;
use CrEOF\Spatial\PHP\Types\Geometry\GeometryInterface;
use Doctrine\DBAL\Platforms\AbstractPlatform;
use Doctrine\DBAL\Types\Type;
Expand All @@ -36,22 +37,32 @@
* @author Derek J. Lambert <[email protected]>
* @license http://dlambert.mit-license.org MIT
*/
abstract class AbstractGeometryType extends Type
abstract class AbstractSpatialType extends Type
{
const PLATFORM_MYSQL = 'MySql';
const PLATFORM_POSTGRESQL = 'PostgreSql';

/**
* @return string
*/
abstract public function getTypeFamily();
public function getTypeFamily()
{
return $this instanceof GeographyType ? GeographyInterface::GEOGRAPHY : GeometryInterface::GEOMETRY;
}

/**
* Gets the SQL name of this type.
*
* @return string
*/
abstract public function getSQLType();
public function getSQLType()
{
$class = get_class($this);
$start = strrpos($class, '\\') + 1;
$len = strlen($class) - $start - 4;

return substr($class, strrpos($class, '\\') + 1, $len);
}

/**
* @return bool
Expand Down Expand Up @@ -138,7 +149,7 @@ public function convertToPHPValue($value, AbstractPlatform $platform)
*/
public function getName()
{
return array_search(get_class($this), $this->getTypesMap());
return array_search(get_class($this), self::getTypesMap(), true);
}

/**
Expand Down
11 changes: 2 additions & 9 deletions lib/CrEOF/Spatial/DBAL/Types/Geography/LineStringType.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php
/**
* Copyright (C) 2012 Derek J. Lambert
* Copyright (C) 2015 Derek J. Lambert
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
Expand All @@ -24,7 +24,6 @@
namespace CrEOF\Spatial\DBAL\Types\Geography;

use CrEOF\Spatial\DBAL\Types\GeographyType;
use CrEOF\Spatial\PHP\Types\Geometry\GeometryInterface;

/**
* Doctrine LINESTRING type
Expand All @@ -34,11 +33,5 @@
*/
class LineStringType extends GeographyType
{
/**
* {@inheritdoc}
*/
public function getSQLType()
{
return GeometryInterface::LINESTRING;
}

}
Loading

0 comments on commit bfd98cb

Please sign in to comment.