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

Commit cdf17d3

Browse files
Mehrdad-DadkhahmikeSimonson
authored andcommitted
fix point value object sample code and point type sample code (#176)
fix point value object sample code and point type sample code.
1 parent 61bbdbf commit cdf17d3

File tree

1 file changed

+11
-5
lines changed

1 file changed

+11
-5
lines changed

en/cookbook/advanced-field-value-conversion-using-custom-mapping-types.rst

+11-5
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,6 @@ The point class:
9292
.. code-block:: php
9393
9494
<?php
95-
9695
namespace Geo\ValueObject;
9796
9897
class Point
@@ -123,6 +122,14 @@ The point class:
123122
{
124123
return $this->longitude;
125124
}
125+
126+
/**
127+
* @return string
128+
*/
129+
public function __toString()
130+
{
131+
return $this->latitude .' '. $this->longitude;
132+
}
126133
}
127134
128135
The mapping type
@@ -138,7 +145,6 @@ Now we're going to create the ``point`` type and implement all required methods.
138145
139146
use Doctrine\DBAL\Types\Type;
140147
use Doctrine\DBAL\Platforms\AbstractPlatform;
141-
142148
use Geo\ValueObject\Point;
143149
144150
class PointType extends Type
@@ -150,22 +156,22 @@ Now we're going to create the ``point`` type and implement all required methods.
150156
return self::POINT;
151157
}
152158
153-
public function getSqlDeclaration(array $fieldDeclaration, AbstractPlatform $platform)
159+
public function getSQLDeclaration(array $fieldDeclaration, AbstractPlatform $platform)
154160
{
155161
return 'POINT';
156162
}
157163
158164
public function convertToPHPValue($value, AbstractPlatform $platform)
159165
{
160-
list($longitude, $latitude) = sscanf($value, 'POINT(%f %f)');
166+
list($latitude, $longitude) = sscanf($value, 'POINT(%f %f)');
161167
162168
return new Point($latitude, $longitude);
163169
}
164170
165171
public function convertToDatabaseValue($value, AbstractPlatform $platform)
166172
{
167173
if ($value instanceof Point) {
168-
$value = sprintf('POINT(%F %F)', $value->getLongitude(), $value->getLatitude());
174+
$value = sprintf('POINT(%F %F)', $value->getLatitude(), $value->getLongitude());
169175
}
170176
171177
return $value;

0 commit comments

Comments
 (0)