Skip to content

Commit afc3010

Browse files
Daniel BerthereauDaniel Berthereau
authored andcommitted
Fixed check of value for coordinates.
1 parent 41c07a4 commit afc3010

3 files changed

Lines changed: 42 additions & 6 deletions

File tree

src/DataType/GeographyCoordinates.php

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,16 +73,28 @@ public function form(PhpRenderer $view)
7373

7474
public function isValid(array $valueObject)
7575
{
76+
// Value is stored as string, but the json representation is an array.
77+
// So the check may be done on the string or on the array.
7678
return !empty($valueObject)
7779
&& !empty($valueObject['@value'])
78-
&& preg_match($this->regexLatitudeLongitude, (string) $valueObject['@value']);
80+
&& preg_match($this->regexLatitudeLongitude,
81+
is_array($valueObject['@value'])
82+
? implode(',', $valueObject['@value'])
83+
: (string) $valueObject['@value']
84+
);
7985
}
8086

8187
public function hydrate(array $valueObject, Value $value, AbstractEntityAdapter $adapter): void
8288
{
8389
// Remove the leading + if any. The value is already checked.
8490
$matches = [];
85-
preg_match($this->regexLatitudeLongitude, (string) $valueObject['@value'], $matches);
91+
preg_match(
92+
$this->regexLatitudeLongitude,
93+
is_array($valueObject['@value'])
94+
? implode(',', $valueObject['@value'])
95+
: (string) $valueObject['@value'],
96+
$matches
97+
);
8698
$latitude = trim($matches['latitude'], '+ ');
8799
$longitude = trim($matches['longitude'], '+ ');
88100
$value->setValue($latitude . ',' . $longitude);

src/DataType/GeometryCoordinates.php

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,16 +67,28 @@ public function form(PhpRenderer $view)
6767

6868
public function isValid(array $valueObject)
6969
{
70+
// Value is stored as string, but the json representation is an array.
71+
// So the check may be done on the string or on the array.
7072
return !empty($valueObject)
7173
&& !empty($valueObject['@value'])
72-
&& preg_match($this->regexCoordinates, (string) $valueObject['@value']);
74+
&& preg_match($this->regexCoordinates,
75+
is_array($valueObject['@value'])
76+
? implode(',', $valueObject['@value'])
77+
: (string) $valueObject['@value']
78+
);
7379
}
7480

7581
public function hydrate(array $valueObject, Value $value, AbstractEntityAdapter $adapter): void
7682
{
7783
// Remove the leading + if any. The value is already checked.
7884
$matches = [];
79-
preg_match($this->regexCoordinates, (string) $valueObject['@value'], $matches);
85+
preg_match(
86+
$this->regexCoordinates,
87+
is_array($valueObject['@value'])
88+
? implode(',', $valueObject['@value'])
89+
: (string) $valueObject['@value'],
90+
$matches
91+
);
8092
$x = trim($matches['x'], '+ ');
8193
$y = trim($matches['y'], '+ ');
8294
$value->setValue($x . ',' . $y);

src/DataType/GeometryPosition.php

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,16 +69,28 @@ public function form(PhpRenderer $view)
6969

7070
public function isValid(array $valueObject)
7171
{
72+
// Value is stored as string, but the json representation is an array.
73+
// So the check may be done on the string or on the array.
7274
return !empty($valueObject)
7375
&& !empty($valueObject['@value'])
74-
&& preg_match($this->regexPosition, (string) $valueObject['@value']);
76+
&& preg_match($this->regexPosition,
77+
is_array($valueObject['@value'])
78+
? implode(',', $valueObject['@value'])
79+
: (string) $valueObject['@value']
80+
);
7581
}
7682

7783
public function hydrate(array $valueObject, Value $value, AbstractEntityAdapter $adapter): void
7884
{
7985
// The value is already checked.
8086
$matches = [];
81-
preg_match($this->regexPosition, (string) $valueObject['@value'], $matches);
87+
preg_match(
88+
$this->regexPosition,
89+
is_array($valueObject['@value'])
90+
? implode(',', $valueObject['@value'])
91+
: (string) $valueObject['@value'],
92+
$matches
93+
);
8294
$x = $matches['x'];
8395
$y = $matches['y'];
8496
$value->setValue($x . ',' . $y);

0 commit comments

Comments
 (0)