Skip to content
This repository has been archived by the owner on Mar 30, 2018. It is now read-only.

Commit

Permalink
fix point value object sample code and point type sample code (#176)
Browse files Browse the repository at this point in the history
fix point value object sample code and point type sample code.
  • Loading branch information
Mehrdad-Dadkhah authored and mikeSimonson committed Nov 8, 2016
1 parent 61bbdbf commit cdf17d3
Showing 1 changed file with 11 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,6 @@ The point class:
.. code-block:: php
<?php
namespace Geo\ValueObject;
class Point
Expand Down Expand Up @@ -123,6 +122,14 @@ The point class:
{
return $this->longitude;
}
/**
* @return string
*/
public function __toString()
{
return $this->latitude .' '. $this->longitude;
}
}
The mapping type
Expand All @@ -138,7 +145,6 @@ Now we're going to create the ``point`` type and implement all required methods.
use Doctrine\DBAL\Types\Type;
use Doctrine\DBAL\Platforms\AbstractPlatform;
use Geo\ValueObject\Point;
class PointType extends Type
Expand All @@ -150,22 +156,22 @@ Now we're going to create the ``point`` type and implement all required methods.
return self::POINT;
}
public function getSqlDeclaration(array $fieldDeclaration, AbstractPlatform $platform)
public function getSQLDeclaration(array $fieldDeclaration, AbstractPlatform $platform)
{
return 'POINT';
}
public function convertToPHPValue($value, AbstractPlatform $platform)
{
list($longitude, $latitude) = sscanf($value, 'POINT(%f %f)');
list($latitude, $longitude) = sscanf($value, 'POINT(%f %f)');
return new Point($latitude, $longitude);
}
public function convertToDatabaseValue($value, AbstractPlatform $platform)
{
if ($value instanceof Point) {
$value = sprintf('POINT(%F %F)', $value->getLongitude(), $value->getLatitude());
$value = sprintf('POINT(%F %F)', $value->getLatitude(), $value->getLongitude());
}
return $value;
Expand Down

0 comments on commit cdf17d3

Please sign in to comment.