Skip to content

Commit

Permalink
Fix parsing in point database type examples.
Browse files Browse the repository at this point in the history
MySQL will not return an array for `POINT` types, but a WKB string,
which needs to be parsed accordingly.
  • Loading branch information
ndm2 committed Sep 21, 2020
1 parent 1e9ba31 commit 01f533b
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 18 deletions.
6 changes: 4 additions & 2 deletions en/orm/database-basics.rst
Original file line number Diff line number Diff line change
Expand Up @@ -519,8 +519,10 @@ PHP::
// Factory method.
public static function parse($value)
{
// Parse the data from MySQL.
return new static($value[0], $value[1]);
// Parse the WKB data from MySQL.
$unpacked = unpack('x4/corder/Ltype/dlat/dlong', $value);

return new static($unpacked['lat'], $unpacked['long']);
}

public function __construct($lat, $long)
Expand Down
12 changes: 7 additions & 5 deletions fr/orm/database-basics.rst
Original file line number Diff line number Diff line change
Expand Up @@ -518,20 +518,22 @@ Comme exemple, nous allons construire une simple classe Type pour manipuler le t
données ``POINT`` de MysQL. Premièrement, nous allons définir un objet 'value' que nous
allons pouvoir utiliser pour représenter les données de ``POINT`` en PHP::

// in src/Database/Point.php
// dans src/Database/Point.php
namespace App\Database;

// Our value object is immutable.
// Notre objet de valeur est immuable.
class Point
{
protected $_lat;
protected $_long;

// Factory method.
// Méthode d'usine.
public static function parse($value)
{
// Parse the data from MySQL.
return new static($value[0], $value[1]);
// Analysez les données WKB de MySQL.
$unpacked = unpack('x4/corder/Ltype/dlat/dlong', $value);

return new static($unpacked['lat'], $unpacked['long']);
}

public function __construct($lat, $long)
Expand Down
6 changes: 4 additions & 2 deletions ja/orm/database-basics.rst
Original file line number Diff line number Diff line change
Expand Up @@ -482,8 +482,10 @@ JSON データを変換してクエリーを作成します。
// ファクトリーメソッド
public static function parse($value)
{
// MySQL からのデータをパース
return new static($value[0], $value[1]);
// MySQLからWKBデータを解析します。
$unpacked = unpack('x4/corder/Ltype/dlat/dlong', $value);

return new static($unpacked['lat'], $unpacked['long']);
}

public function __construct($lat, $long)
Expand Down
12 changes: 7 additions & 5 deletions pt/orm/database-basics.rst
Original file line number Diff line number Diff line change
Expand Up @@ -465,20 +465,22 @@ expressão SQL. Como exemplo, nós vamos construir uma simples classe Type para
manipular dados do tipo ``POINT`` do MySQL. Primeiramente, vamos definir um
objeto 'value' que podemos usar para representar dados ``POINT`` no PHP::

// in src/Database/Point.php
// no src/Database/Point.php
namespace App\Database;

// Our value object is immutable.
// Nosso objeto de valor é imutável.
class Point
{
protected $_lat;
protected $_long;

// Factory method.
// Método de fábrica.
public static function parse($value)
{
// Parse the data from MySQL.
return new static($value[0], $value[1]);
// Analise os dados WKB do MySQL.
$unpacked = unpack('x4/corder/Ltype/dlat/dlong', $value);

return new static($unpacked['lat'], $unpacked['long']);
}

public function __construct($lat, $long)
Expand Down
6 changes: 4 additions & 2 deletions ru/orm/database-basics.rst
Original file line number Diff line number Diff line change
Expand Up @@ -482,8 +482,10 @@ json
// Factory метод.
public static function parse($value)
{
// Парсинг данных из MySQL.
return new static($value[0], $value[1]);
// Разберите данные WKB из MySQL.
$unpacked = unpack('x4/corder/Ltype/dlat/dlong', $value);

return new static($unpacked['lat'], $unpacked['long']);
}

public function __construct($lat, $long)
Expand Down
6 changes: 4 additions & 2 deletions tl/orm/database-basics.rst
Original file line number Diff line number Diff line change
Expand Up @@ -493,8 +493,10 @@ PHP::
// Factory method.
public static function parse($value)
{
// Parse the data from MySQL.
return new static($value[0], $value[1]);
// Parse the WKB data from MySQL.
$unpacked = unpack('x4/corder/Ltype/dlat/dlong', $value);

return new static($unpacked['lat'], $unpacked['long']);
}

public function __construct($lat, $long)
Expand Down

0 comments on commit 01f533b

Please sign in to comment.