|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/* |
|
4
|
|
|
* This file is part of the geo-api-library package. |
|
5
|
|
|
* |
|
6
|
|
|
* (c) 2020 WEBEWEB |
|
7
|
|
|
* |
|
8
|
|
|
* For the full copyright and license information, please view the LICENSE |
|
9
|
|
|
* file that was distributed with this source code. |
|
10
|
|
|
*/ |
|
11
|
|
|
|
|
12
|
|
|
namespace WBW\Library\GeoAPI\Serializer; |
|
13
|
|
|
|
|
14
|
|
|
use WBW\Library\Core\Argument\Helper\ArrayHelper; |
|
15
|
|
|
use WBW\Library\GeoAPI\Model\Region; |
|
16
|
|
|
use WBW\Library\GeoAPI\Model\Response\Region\ListeRegionsResponse; |
|
17
|
|
|
|
|
18
|
|
|
/** |
|
19
|
|
|
* Région response deserializer. |
|
20
|
|
|
* |
|
21
|
|
|
* @author webeweb <https://github.com/webeweb/> |
|
22
|
|
|
* @package WBW\Library\GeoAPI\Serializer |
|
23
|
|
|
*/ |
|
24
|
|
|
class RegionResponseDeserializer { |
|
25
|
|
|
|
|
26
|
|
|
/** |
|
27
|
|
|
* Deserializes a liste régions response. |
|
28
|
|
|
* |
|
29
|
|
|
* @param string $rawResponse The raw response. |
|
30
|
|
|
* @return ListeRegionsResponse Returns the liste régions response. |
|
31
|
|
|
*/ |
|
32
|
|
|
public static function deserializeListeRegionsResponse($rawResponse) { |
|
33
|
|
|
|
|
34
|
|
|
$model = new ListeRegionsResponse(); |
|
35
|
|
|
$model->setRawResponse($rawResponse); |
|
36
|
|
|
|
|
37
|
|
|
$response = json_decode($rawResponse, true); |
|
38
|
|
|
if (null === $response) { |
|
39
|
|
|
return $model; |
|
40
|
|
|
} |
|
41
|
|
|
|
|
42
|
|
|
foreach ($response as $current) { |
|
43
|
|
|
$model->addRegion(static::deserializeRegion($current)); |
|
44
|
|
|
} |
|
45
|
|
|
|
|
46
|
|
|
return $model; |
|
47
|
|
|
} |
|
48
|
|
|
|
|
49
|
|
|
/** |
|
50
|
|
|
* Deserializes a région. |
|
51
|
|
|
* |
|
52
|
|
|
* @param array $response The response. |
|
53
|
|
|
* @return Region Returns the région. |
|
54
|
|
|
*/ |
|
55
|
|
|
public static function deserializeRegion(array $response) { |
|
56
|
|
|
|
|
57
|
|
|
$model = new Region(); |
|
58
|
|
|
$model->setCode(ArrayHelper::get($response, "code")); |
|
59
|
|
|
$model->setNom(ArrayHelper::get($response, "nom")); |
|
60
|
|
|
$model->setScore(ArrayHelper::get($response, "_score")); |
|
61
|
|
|
|
|
62
|
|
|
return $model; |
|
63
|
|
|
} |
|
64
|
|
|
} |