1
|
|
|
<?php |
2
|
|
|
declare(strict_types=1); |
3
|
|
|
|
4
|
|
|
namespace Bpost\BpostApiClient\Geo6; |
5
|
|
|
|
6
|
|
|
use Bpost\BpostApiClient\Exception\BpostApiResponseException\BpostInvalidXmlResponseException; |
7
|
|
|
use SimpleXMLElement; |
8
|
|
|
|
9
|
|
|
/** |
10
|
|
|
* Geo6 class |
11
|
|
|
* |
12
|
|
|
* @author Tijs Verkoyen <[email protected]> |
13
|
|
|
* |
14
|
|
|
* @version 3.0.0 |
15
|
|
|
* |
16
|
|
|
* @copyright Copyright (c), Tijs Verkoyen. All rights reserved. |
17
|
|
|
* @license BSD License |
18
|
|
|
*/ |
19
|
|
|
class Poi |
20
|
|
|
{ |
21
|
|
|
private ?string $id = null; |
22
|
|
|
private ?string $type = null; |
23
|
|
|
private ?string $office = null; |
24
|
|
|
private ?string $street = null; |
25
|
|
|
private ?string $nr = null; |
26
|
|
|
private ?string $zip = null; |
27
|
|
|
private ?string $city = null; |
28
|
|
|
private ?int $x = null; |
29
|
|
|
private ?int $y = null; |
30
|
|
|
private ?float $latitude = null; |
31
|
|
|
private ?float $longitude = null; |
32
|
|
|
|
33
|
|
|
/** @var Service[] */ |
34
|
|
|
private array $services = []; |
35
|
|
|
|
36
|
|
|
/** @var array<int, Day> Indexed by Day::DAY_INDEX_* */ |
37
|
|
|
private array $hours = []; |
38
|
|
|
|
39
|
|
|
private ?string $closedFrom = null; |
40
|
|
|
private ?string $closedTo = null; |
41
|
|
|
private ?string $note = null; |
42
|
|
|
private ?string $page = null; |
43
|
|
|
|
44
|
|
|
public function getId(): ?string |
45
|
|
|
{ |
46
|
|
|
return $this->id; |
47
|
|
|
} |
48
|
|
|
|
49
|
|
|
public function setId(?string $id): void |
50
|
|
|
{ |
51
|
|
|
$this->id = $id; |
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
public function getType(): ?string |
55
|
|
|
{ |
56
|
|
|
return $this->type; |
57
|
|
|
} |
58
|
|
|
|
59
|
|
|
public function setType(?string $type): void |
60
|
|
|
{ |
61
|
|
|
$this->type = $type; |
62
|
|
|
} |
63
|
|
|
|
64
|
|
|
public function getOffice(): ?string |
65
|
|
|
{ |
66
|
|
|
return $this->office; |
67
|
|
|
} |
68
|
|
|
|
69
|
|
|
public function setOffice(?string $office): void |
70
|
|
|
{ |
71
|
|
|
$this->office = $office; |
72
|
|
|
} |
73
|
|
|
|
74
|
|
|
public function getStreet(): ?string |
75
|
|
|
{ |
76
|
|
|
return $this->street; |
77
|
|
|
} |
78
|
|
|
|
79
|
|
|
public function setStreet(?string $street): void |
80
|
|
|
{ |
81
|
|
|
$this->street = $street; |
82
|
|
|
} |
83
|
|
|
|
84
|
|
|
public function getNr(): ?string |
85
|
|
|
{ |
86
|
|
|
return $this->nr; |
87
|
|
|
} |
88
|
|
|
|
89
|
|
|
public function setNr(?string $nr): void |
90
|
|
|
{ |
91
|
|
|
$this->nr = $nr; |
92
|
|
|
} |
93
|
|
|
|
94
|
|
|
public function getZip(): ?string |
95
|
|
|
{ |
96
|
|
|
return $this->zip; |
97
|
|
|
} |
98
|
|
|
|
99
|
|
|
public function setZip(?string $zip): void |
100
|
|
|
{ |
101
|
|
|
$this->zip = $zip; |
102
|
|
|
} |
103
|
|
|
|
104
|
|
|
public function getCity(): ?string |
105
|
|
|
{ |
106
|
|
|
return $this->city; |
107
|
|
|
} |
108
|
|
|
|
109
|
|
|
public function setCity(?string $city): void |
110
|
|
|
{ |
111
|
|
|
$this->city = $city; |
112
|
|
|
} |
113
|
|
|
|
114
|
|
|
public function getX(): ?int |
115
|
|
|
{ |
116
|
|
|
return $this->x; |
117
|
|
|
} |
118
|
|
|
|
119
|
|
|
public function setX(?int $x): void |
120
|
|
|
{ |
121
|
|
|
$this->x = $x; |
122
|
|
|
} |
123
|
|
|
|
124
|
|
|
public function getY(): ?int |
125
|
|
|
{ |
126
|
|
|
return $this->y; |
127
|
|
|
} |
128
|
|
|
|
129
|
|
|
public function setY(?int $y): void |
130
|
|
|
{ |
131
|
|
|
$this->y = $y; |
132
|
|
|
} |
133
|
|
|
|
134
|
|
|
public function getLatitude(): ?float |
135
|
|
|
{ |
136
|
|
|
return $this->latitude; |
137
|
|
|
} |
138
|
|
|
|
139
|
|
|
public function setLatitude(?float $latitude): void |
140
|
|
|
{ |
141
|
|
|
$this->latitude = $latitude; |
142
|
|
|
} |
143
|
|
|
|
144
|
|
|
public function getLongitude(): ?float |
145
|
|
|
{ |
146
|
|
|
return $this->longitude; |
147
|
|
|
} |
148
|
|
|
|
149
|
|
|
public function setLongitude(?float $longitude): void |
150
|
|
|
{ |
151
|
|
|
$this->longitude = $longitude; |
152
|
|
|
} |
153
|
|
|
|
154
|
|
|
public function getServices(): array |
155
|
|
|
{ |
156
|
|
|
return $this->services; |
157
|
|
|
} |
158
|
|
|
|
159
|
|
|
public function addService(Service $service): void |
160
|
|
|
{ |
161
|
|
|
$this->services[] = $service; |
162
|
|
|
} |
163
|
|
|
|
164
|
|
|
public function setServices(array $services): void |
165
|
|
|
{ |
166
|
|
|
$this->services = $services; |
167
|
|
|
} |
168
|
|
|
|
169
|
|
|
public function getHours(): array |
170
|
|
|
{ |
171
|
|
|
return $this->hours; |
172
|
|
|
} |
173
|
|
|
|
174
|
|
|
public function addHour(int $index, Day $day): void |
175
|
|
|
{ |
176
|
|
|
$this->hours[$index] = $day; |
177
|
|
|
} |
178
|
|
|
|
179
|
|
|
public function setHours(array $hours): void |
180
|
|
|
{ |
181
|
|
|
$this->hours = $hours; |
182
|
|
|
} |
183
|
|
|
|
184
|
|
|
public function getClosedFrom(): ?string |
185
|
|
|
{ |
186
|
|
|
return $this->closedFrom; |
187
|
|
|
} |
188
|
|
|
|
189
|
|
|
public function setClosedFrom(?string $closedFrom): void |
190
|
|
|
{ |
191
|
|
|
$this->closedFrom = $closedFrom; |
192
|
|
|
} |
193
|
|
|
|
194
|
|
|
public function getClosedTo(): ?string |
195
|
|
|
{ |
196
|
|
|
return $this->closedTo; |
197
|
|
|
} |
198
|
|
|
|
199
|
|
|
public function setClosedTo(?string $closedTo): void |
200
|
|
|
{ |
201
|
|
|
$this->closedTo = $closedTo; |
202
|
|
|
} |
203
|
|
|
|
204
|
|
|
public function getNote(): ?string |
205
|
|
|
{ |
206
|
|
|
return $this->note; |
207
|
|
|
} |
208
|
|
|
|
209
|
|
|
public function setNote(?string $note): void |
210
|
|
|
{ |
211
|
|
|
$this->note = $note; |
212
|
|
|
} |
213
|
|
|
|
214
|
|
|
public function getPage(): ?string |
215
|
|
|
{ |
216
|
|
|
return $this->page; |
217
|
|
|
} |
218
|
|
|
|
219
|
|
|
public function setPage(?string $page): void |
220
|
|
|
{ |
221
|
|
|
$this->page = $page; |
222
|
|
|
} |
223
|
|
|
|
224
|
|
|
public static function createFromXML(SimpleXMLElement $xml): self |
225
|
|
|
{ |
226
|
|
|
if (!isset($xml->Record)) { |
227
|
|
|
throw new BpostInvalidXmlResponseException('"Record" missing'); |
228
|
|
|
} |
229
|
|
|
|
230
|
|
|
$recordXml = $xml->Record; |
231
|
|
|
$poi = new self(); |
232
|
|
|
|
233
|
|
|
// Identifiants / type / nom |
234
|
|
|
if (isset($recordXml->Id) && (string)$recordXml->Id !== '') { $poi->setId((string)$recordXml->Id); } |
235
|
|
|
if (isset($recordXml->ID) && (string)$recordXml->ID !== '') { $poi->setId((string)$recordXml->ID); } |
236
|
|
|
|
237
|
|
|
if (isset($recordXml->Type) && (string)$recordXml->Type !== '') { $poi->setType((string)$recordXml->Type); } |
238
|
|
|
|
239
|
|
|
if (isset($recordXml->Name) && (string)$recordXml->Name !== '') { $poi->setOffice((string)$recordXml->Name); } |
240
|
|
|
if (isset($recordXml->OFFICE) && (string)$recordXml->OFFICE !== '') { $poi->setOffice((string)$recordXml->OFFICE); } |
241
|
|
|
|
242
|
|
|
// Adresse |
243
|
|
|
if (isset($recordXml->Street) && (string)$recordXml->Street !== '') { $poi->setStreet((string)$recordXml->Street); } |
244
|
|
|
if (isset($recordXml->STREET) && (string)$recordXml->STREET !== '') { $poi->setStreet((string)$recordXml->STREET); } |
245
|
|
|
|
246
|
|
|
if (isset($recordXml->Number) && (string)$recordXml->Number !== '') { $poi->setNr((string)$recordXml->Number); } |
247
|
|
|
if (isset($recordXml->NR) && (string)$recordXml->NR !== '') { $poi->setNr((string)$recordXml->NR); } |
248
|
|
|
|
249
|
|
|
if (isset($recordXml->Zip) && (string)$recordXml->Zip !== '') { $poi->setZip((string)$recordXml->Zip); } |
250
|
|
|
if (isset($recordXml->ZIP) && (string)$recordXml->ZIP !== '') { $poi->setZip((string)$recordXml->ZIP); } |
251
|
|
|
|
252
|
|
|
if (isset($recordXml->City) && (string)$recordXml->City !== '') { $poi->setCity((string)$recordXml->City); } |
253
|
|
|
if (isset($recordXml->CITY) && (string)$recordXml->CITY !== '') { $poi->setCity((string)$recordXml->CITY); } |
254
|
|
|
|
255
|
|
|
// Coordonnées |
256
|
|
|
if (isset($recordXml->X) && (string)$recordXml->X !== '') { $poi->setX((int)$recordXml->X); } |
257
|
|
|
if (isset($recordXml->Y) && (string)$recordXml->Y !== '') { $poi->setY((int)$recordXml->Y); } |
258
|
|
|
if (isset($recordXml->Longitude) && (string)$recordXml->Longitude !== '') { $poi->setLongitude((float)$recordXml->Longitude); } |
259
|
|
|
if (isset($recordXml->Latitude) && (string)$recordXml->Latitude !== '') { $poi->setLatitude((float)$recordXml->Latitude); } |
260
|
|
|
|
261
|
|
|
// Services |
262
|
|
|
if (isset($recordXml->Services) && isset($recordXml->Services->Service)) { |
263
|
|
|
foreach ($recordXml->Services->Service as $serviceXml) { |
264
|
|
|
$poi->addService(Service::createFromXML($serviceXml)); |
265
|
|
|
} |
266
|
|
|
} |
267
|
|
|
|
268
|
|
|
if (isset($recordXml->Hours)) { |
269
|
|
|
$hours = $recordXml->Hours; |
270
|
|
|
|
271
|
|
|
if (isset($hours->Monday)) { $poi->addHour(Day::DAY_INDEX_MONDAY, Day::createFromXML($hours->Monday)); } |
272
|
|
|
if (isset($hours->Tuesday)) { $poi->addHour(Day::DAY_INDEX_TUESDAY, Day::createFromXML($hours->Tuesday)); } |
273
|
|
|
if (isset($hours->Wednesday)) { $poi->addHour(Day::DAY_INDEX_WEDNESDAY, Day::createFromXML($hours->Wednesday)); } |
274
|
|
|
if (isset($hours->Thursday)) { $poi->addHour(Day::DAY_INDEX_THURSDAY, Day::createFromXML($hours->Thursday)); } |
275
|
|
|
if (isset($hours->Friday)) { $poi->addHour(Day::DAY_INDEX_FRIDAY, Day::createFromXML($hours->Friday)); } |
276
|
|
|
if (isset($hours->Saturday)) { $poi->addHour(Day::DAY_INDEX_SATURDAY, Day::createFromXML($hours->Saturday)); } |
277
|
|
|
if (isset($hours->Sunday)) { $poi->addHour(Day::DAY_INDEX_SUNDAY, Day::createFromXML($hours->Sunday)); } |
278
|
|
|
} |
279
|
|
|
|
280
|
|
|
if (isset($recordXml->ClosedFrom) && (string)$recordXml->ClosedFrom !== '') { $poi->setClosedFrom((string)$recordXml->ClosedFrom); } |
281
|
|
|
if (isset($recordXml->ClosedTo) && (string)$recordXml->ClosedTo !== '') { $poi->setClosedTo((string)$recordXml->ClosedTo); } |
282
|
|
|
|
283
|
|
|
// Note |
284
|
|
|
if (isset($recordXml->NOTE) && (string)$recordXml->NOTE !== '') { $poi->setNote((string)$recordXml->NOTE); } |
285
|
|
|
|
286
|
|
|
// Lien page |
287
|
|
|
if (isset($xml->Page) && isset($xml->Page['ServiceRef']) && (string)$xml->Page['ServiceRef'] !== '') { |
288
|
|
|
$poi->setPage((string)$xml->Page['ServiceRef']); |
289
|
|
|
} |
290
|
|
|
|
291
|
|
|
return $poi; |
292
|
|
|
} |
293
|
|
|
} |