|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
/* |
|
6
|
|
|
* This file is part of the Geocoder package. |
|
7
|
|
|
* For the full copyright and license information, please view the LICENSE |
|
8
|
|
|
* file that was distributed with this source code. |
|
9
|
|
|
* |
|
10
|
|
|
* @license MIT License |
|
11
|
|
|
*/ |
|
12
|
|
|
|
|
13
|
|
|
namespace Geocoder\Provider\GoogleMaps\Model; |
|
14
|
|
|
|
|
15
|
|
|
use Geocoder\Model\Address; |
|
16
|
|
|
use Geocoder\Model\AdminLevel; |
|
17
|
|
|
use Geocoder\Model\AdminLevelCollection; |
|
18
|
|
|
|
|
19
|
|
|
/** |
|
20
|
|
|
* @author Tobias Nyholm <[email protected]> |
|
21
|
|
|
*/ |
|
22
|
|
|
final class GoogleAddress extends Address |
|
23
|
|
|
{ |
|
24
|
|
|
/** |
|
25
|
|
|
* @var string|null |
|
26
|
|
|
*/ |
|
27
|
|
|
private $id; |
|
28
|
|
|
|
|
29
|
|
|
/** |
|
30
|
|
|
* @var string|null |
|
31
|
|
|
*/ |
|
32
|
|
|
private $locationType; |
|
33
|
|
|
|
|
34
|
|
|
/** |
|
35
|
|
|
* @var array |
|
36
|
|
|
*/ |
|
37
|
|
|
private $resultType = []; |
|
38
|
|
|
|
|
39
|
|
|
/** |
|
40
|
|
|
* @var string|null |
|
41
|
|
|
*/ |
|
42
|
|
|
private $formattedAddress; |
|
43
|
|
|
|
|
44
|
|
|
/** |
|
45
|
|
|
* @var string|null |
|
46
|
|
|
*/ |
|
47
|
|
|
private $streetAddress; |
|
48
|
|
|
|
|
49
|
|
|
/** |
|
50
|
|
|
* @var string|null |
|
51
|
|
|
*/ |
|
52
|
|
|
private $intersection; |
|
53
|
|
|
|
|
54
|
|
|
/** |
|
55
|
|
|
* @var string|null |
|
56
|
|
|
*/ |
|
57
|
|
|
private $postalCodeSuffix; |
|
58
|
|
|
|
|
59
|
|
|
/** |
|
60
|
|
|
* @var string|null |
|
61
|
|
|
*/ |
|
62
|
|
|
private $political; |
|
63
|
|
|
|
|
64
|
|
|
/** |
|
65
|
|
|
* @var string|null |
|
66
|
|
|
*/ |
|
67
|
|
|
private $colloquialArea; |
|
68
|
|
|
|
|
69
|
|
|
/** |
|
70
|
|
|
* @var string|null |
|
71
|
|
|
*/ |
|
72
|
|
|
private $ward; |
|
73
|
|
|
|
|
74
|
|
|
/** |
|
75
|
|
|
* @var string|null |
|
76
|
|
|
*/ |
|
77
|
|
|
private $neighborhood; |
|
78
|
|
|
|
|
79
|
|
|
/** |
|
80
|
|
|
* @var string|null |
|
81
|
|
|
*/ |
|
82
|
|
|
private $premise; |
|
83
|
|
|
|
|
84
|
|
|
/** |
|
85
|
|
|
* @var string|null |
|
86
|
|
|
*/ |
|
87
|
|
|
private $subpremise; |
|
88
|
|
|
|
|
89
|
|
|
/** |
|
90
|
|
|
* @var string|null |
|
91
|
|
|
*/ |
|
92
|
|
|
private $naturalFeature; |
|
93
|
|
|
|
|
94
|
|
|
/** |
|
95
|
|
|
* @var string|null |
|
96
|
|
|
*/ |
|
97
|
|
|
private $airport; |
|
98
|
|
|
|
|
99
|
|
|
/** |
|
100
|
|
|
* @var string|null |
|
101
|
|
|
*/ |
|
102
|
|
|
private $park; |
|
103
|
|
|
|
|
104
|
|
|
/** |
|
105
|
|
|
* @var string|null |
|
106
|
|
|
*/ |
|
107
|
|
|
private $pointOfInterest; |
|
108
|
|
|
|
|
109
|
|
|
/** |
|
110
|
|
|
* @var string|null |
|
111
|
|
|
*/ |
|
112
|
|
|
private $establishment; |
|
113
|
|
|
|
|
114
|
|
|
/** |
|
115
|
|
|
* @var AdminLevelCollection |
|
116
|
|
|
*/ |
|
117
|
|
|
private $subLocalityLevels; |
|
118
|
|
|
|
|
119
|
|
|
/** |
|
120
|
|
|
* @var bool |
|
121
|
|
|
*/ |
|
122
|
|
|
private $partialMatch; |
|
123
|
|
|
|
|
124
|
|
|
/** |
|
125
|
|
|
* @param null|string $id |
|
126
|
|
|
* |
|
127
|
|
|
* @return GoogleAddress |
|
128
|
|
|
*/ |
|
129
|
18 |
|
public function withId(string $id = null) |
|
130
|
|
|
{ |
|
131
|
18 |
|
$new = clone $this; |
|
132
|
18 |
|
$new->id = $id; |
|
133
|
|
|
|
|
134
|
18 |
|
return $new; |
|
135
|
|
|
} |
|
136
|
|
|
|
|
137
|
|
|
/** |
|
138
|
|
|
* @see https://developers.google.com/places/place-id |
|
139
|
|
|
* |
|
140
|
|
|
* @return null|string |
|
141
|
|
|
*/ |
|
142
|
4 |
|
public function getId() |
|
143
|
|
|
{ |
|
144
|
4 |
|
return $this->id; |
|
145
|
|
|
} |
|
146
|
|
|
|
|
147
|
|
|
/** |
|
148
|
|
|
* @param null|string $locationType |
|
149
|
|
|
* |
|
150
|
|
|
* @return GoogleAddress |
|
151
|
|
|
*/ |
|
152
|
18 |
|
public function withLocationType(string $locationType = null) |
|
153
|
|
|
{ |
|
154
|
18 |
|
$new = clone $this; |
|
155
|
18 |
|
$new->locationType = $locationType; |
|
156
|
|
|
|
|
157
|
18 |
|
return $new; |
|
158
|
|
|
} |
|
159
|
|
|
|
|
160
|
|
|
/** |
|
161
|
|
|
* @return null|string |
|
162
|
|
|
*/ |
|
163
|
|
|
public function getLocationType() |
|
164
|
|
|
{ |
|
165
|
|
|
return $this->locationType; |
|
166
|
|
|
} |
|
167
|
|
|
|
|
168
|
|
|
/** |
|
169
|
|
|
* @return array |
|
170
|
|
|
*/ |
|
171
|
|
|
public function getResultType(): array |
|
172
|
|
|
{ |
|
173
|
|
|
return $this->resultType; |
|
174
|
|
|
} |
|
175
|
|
|
|
|
176
|
|
|
/** |
|
177
|
|
|
* @param array $resultType |
|
178
|
|
|
* |
|
179
|
|
|
* @return GoogleAddress |
|
180
|
|
|
*/ |
|
181
|
18 |
|
public function withResultType(array $resultType) |
|
182
|
|
|
{ |
|
183
|
18 |
|
$new = clone $this; |
|
184
|
18 |
|
$new->resultType = $resultType; |
|
185
|
|
|
|
|
186
|
18 |
|
return $new; |
|
187
|
|
|
} |
|
188
|
|
|
|
|
189
|
|
|
/** |
|
190
|
|
|
* @return null|string |
|
191
|
|
|
*/ |
|
192
|
1 |
|
public function getFormattedAddress() |
|
193
|
|
|
{ |
|
194
|
1 |
|
return $this->formattedAddress; |
|
195
|
|
|
} |
|
196
|
|
|
|
|
197
|
|
|
/** |
|
198
|
|
|
* @param string|null $formattedAddress |
|
199
|
|
|
* |
|
200
|
|
|
* @return GoogleAddress |
|
201
|
|
|
*/ |
|
202
|
18 |
|
public function withFormattedAddress(string $formattedAddress = null) |
|
203
|
|
|
{ |
|
204
|
18 |
|
$new = clone $this; |
|
205
|
18 |
|
$new->formattedAddress = $formattedAddress; |
|
206
|
|
|
|
|
207
|
18 |
|
return $new; |
|
208
|
|
|
} |
|
209
|
|
|
|
|
210
|
|
|
/** |
|
211
|
|
|
* @return null|string |
|
212
|
|
|
*/ |
|
213
|
1 |
|
public function getAirport() |
|
214
|
|
|
{ |
|
215
|
1 |
|
return $this->airport; |
|
216
|
|
|
} |
|
217
|
|
|
|
|
218
|
|
|
/** |
|
219
|
|
|
* @param string|null $airport |
|
220
|
|
|
* |
|
221
|
|
|
* @return GoogleAddress |
|
222
|
|
|
*/ |
|
223
|
18 |
|
public function withAirport(string $airport = null) |
|
224
|
|
|
{ |
|
225
|
18 |
|
$new = clone $this; |
|
226
|
18 |
|
$new->airport = $airport; |
|
227
|
|
|
|
|
228
|
18 |
|
return $new; |
|
229
|
|
|
} |
|
230
|
|
|
|
|
231
|
|
|
/** |
|
232
|
|
|
* @return null|string |
|
233
|
|
|
*/ |
|
234
|
1 |
|
public function getColloquialArea() |
|
235
|
|
|
{ |
|
236
|
1 |
|
return $this->colloquialArea; |
|
237
|
|
|
} |
|
238
|
|
|
|
|
239
|
|
|
/** |
|
240
|
|
|
* @param string|null $colloquialArea |
|
241
|
|
|
* |
|
242
|
|
|
* @return GoogleAddress |
|
243
|
|
|
*/ |
|
244
|
18 |
|
public function withColloquialArea(string $colloquialArea = null) |
|
245
|
|
|
{ |
|
246
|
18 |
|
$new = clone $this; |
|
247
|
18 |
|
$new->colloquialArea = $colloquialArea; |
|
248
|
|
|
|
|
249
|
18 |
|
return $new; |
|
250
|
|
|
} |
|
251
|
|
|
|
|
252
|
|
|
/** |
|
253
|
|
|
* @return null|string |
|
254
|
|
|
*/ |
|
255
|
|
|
public function getIntersection() |
|
256
|
|
|
{ |
|
257
|
|
|
return $this->intersection; |
|
258
|
|
|
} |
|
259
|
|
|
|
|
260
|
|
|
/** |
|
261
|
|
|
* @param string|null $intersection |
|
262
|
|
|
* |
|
263
|
|
|
* @return GoogleAddress |
|
264
|
|
|
*/ |
|
265
|
18 |
|
public function withIntersection(string $intersection = null) |
|
266
|
|
|
{ |
|
267
|
18 |
|
$new = clone $this; |
|
268
|
18 |
|
$new->intersection = $intersection; |
|
269
|
|
|
|
|
270
|
18 |
|
return $new; |
|
271
|
|
|
} |
|
272
|
|
|
|
|
273
|
|
|
/** |
|
274
|
|
|
* @return null|string |
|
275
|
|
|
*/ |
|
276
|
2 |
|
public function getPostalCodeSuffix() |
|
277
|
|
|
{ |
|
278
|
2 |
|
return $this->postalCodeSuffix; |
|
279
|
|
|
} |
|
280
|
|
|
|
|
281
|
|
|
/** |
|
282
|
|
|
* @param string|null $postalCodeSuffix |
|
283
|
|
|
* |
|
284
|
|
|
* @return GoogleAddress |
|
285
|
|
|
*/ |
|
286
|
18 |
|
public function withPostalCodeSuffix(string $postalCodeSuffix = null) |
|
287
|
|
|
{ |
|
288
|
18 |
|
$new = clone $this; |
|
289
|
18 |
|
$new->postalCodeSuffix = $postalCodeSuffix; |
|
290
|
|
|
|
|
291
|
18 |
|
return $new; |
|
292
|
|
|
} |
|
293
|
|
|
|
|
294
|
|
|
/** |
|
295
|
|
|
* @return null|string |
|
296
|
|
|
*/ |
|
297
|
1 |
|
public function getNaturalFeature() |
|
298
|
|
|
{ |
|
299
|
1 |
|
return $this->naturalFeature; |
|
300
|
|
|
} |
|
301
|
|
|
|
|
302
|
|
|
/** |
|
303
|
|
|
* @param string|null $naturalFeature |
|
304
|
|
|
* |
|
305
|
|
|
* @return GoogleAddress |
|
306
|
|
|
*/ |
|
307
|
18 |
|
public function withNaturalFeature(string $naturalFeature = null) |
|
308
|
|
|
{ |
|
309
|
18 |
|
$new = clone $this; |
|
310
|
18 |
|
$new->naturalFeature = $naturalFeature; |
|
311
|
|
|
|
|
312
|
18 |
|
return $new; |
|
313
|
|
|
} |
|
314
|
|
|
|
|
315
|
|
|
/** |
|
316
|
|
|
* @return null|string |
|
317
|
|
|
*/ |
|
318
|
1 |
|
public function getNeighborhood() |
|
319
|
|
|
{ |
|
320
|
1 |
|
return $this->neighborhood; |
|
321
|
|
|
} |
|
322
|
|
|
|
|
323
|
|
|
/** |
|
324
|
|
|
* @param string|null $neighborhood |
|
325
|
|
|
* |
|
326
|
|
|
* @return GoogleAddress |
|
327
|
|
|
*/ |
|
328
|
18 |
|
public function withNeighborhood(string $neighborhood = null) |
|
329
|
|
|
{ |
|
330
|
18 |
|
$new = clone $this; |
|
331
|
18 |
|
$new->neighborhood = $neighborhood; |
|
332
|
|
|
|
|
333
|
18 |
|
return $new; |
|
334
|
|
|
} |
|
335
|
|
|
|
|
336
|
|
|
/** |
|
337
|
|
|
* @return null|string |
|
338
|
|
|
*/ |
|
339
|
1 |
|
public function getPark() |
|
340
|
|
|
{ |
|
341
|
1 |
|
return $this->park; |
|
342
|
|
|
} |
|
343
|
|
|
|
|
344
|
|
|
/** |
|
345
|
|
|
* @param string|null $park |
|
346
|
|
|
* |
|
347
|
|
|
* @return GoogleAddress |
|
348
|
|
|
*/ |
|
349
|
18 |
|
public function withPark(string $park = null) |
|
350
|
|
|
{ |
|
351
|
18 |
|
$new = clone $this; |
|
352
|
18 |
|
$new->park = $park; |
|
353
|
|
|
|
|
354
|
18 |
|
return $new; |
|
355
|
|
|
} |
|
356
|
|
|
|
|
357
|
|
|
/** |
|
358
|
|
|
* @return null|string |
|
359
|
|
|
*/ |
|
360
|
2 |
|
public function getPointOfInterest() |
|
361
|
|
|
{ |
|
362
|
2 |
|
return $this->pointOfInterest; |
|
363
|
|
|
} |
|
364
|
|
|
|
|
365
|
|
|
/** |
|
366
|
|
|
* @param string|null $pointOfInterest |
|
367
|
|
|
* |
|
368
|
|
|
* @return GoogleAddress |
|
369
|
|
|
*/ |
|
370
|
18 |
|
public function withPointOfInterest(string $pointOfInterest = null) |
|
371
|
|
|
{ |
|
372
|
18 |
|
$new = clone $this; |
|
373
|
18 |
|
$new->pointOfInterest = $pointOfInterest; |
|
374
|
|
|
|
|
375
|
18 |
|
return $new; |
|
376
|
|
|
} |
|
377
|
|
|
|
|
378
|
|
|
/** |
|
379
|
|
|
* @return null|string |
|
380
|
|
|
*/ |
|
381
|
1 |
|
public function getPolitical() |
|
382
|
|
|
{ |
|
383
|
1 |
|
return $this->political; |
|
384
|
|
|
} |
|
385
|
|
|
|
|
386
|
|
|
/** |
|
387
|
|
|
* @param string|null $political |
|
388
|
|
|
* |
|
389
|
|
|
* @return GoogleAddress |
|
390
|
|
|
*/ |
|
391
|
18 |
|
public function withPolitical(string $political = null) |
|
392
|
|
|
{ |
|
393
|
18 |
|
$new = clone $this; |
|
394
|
18 |
|
$new->political = $political; |
|
395
|
|
|
|
|
396
|
18 |
|
return $new; |
|
397
|
|
|
} |
|
398
|
|
|
|
|
399
|
|
|
/** |
|
400
|
|
|
* @return null|string |
|
401
|
|
|
*/ |
|
402
|
1 |
|
public function getPremise() |
|
403
|
|
|
{ |
|
404
|
1 |
|
return $this->premise; |
|
405
|
|
|
} |
|
406
|
|
|
|
|
407
|
|
|
/** |
|
408
|
|
|
* @param string $premise |
|
409
|
|
|
* |
|
410
|
|
|
* @return GoogleAddress |
|
411
|
|
|
*/ |
|
412
|
18 |
|
public function withPremise(string $premise = null) |
|
413
|
|
|
{ |
|
414
|
18 |
|
$new = clone $this; |
|
415
|
18 |
|
$new->premise = $premise; |
|
416
|
|
|
|
|
417
|
18 |
|
return $new; |
|
418
|
|
|
} |
|
419
|
|
|
|
|
420
|
|
|
/** |
|
421
|
|
|
* @return null|string |
|
422
|
|
|
*/ |
|
423
|
|
|
public function getStreetAddress() |
|
424
|
|
|
{ |
|
425
|
|
|
return $this->streetAddress; |
|
426
|
|
|
} |
|
427
|
|
|
|
|
428
|
|
|
/** |
|
429
|
|
|
* @param string|null $streetAddress |
|
430
|
|
|
* |
|
431
|
|
|
* @return GoogleAddress |
|
432
|
|
|
*/ |
|
433
|
18 |
|
public function withStreetAddress(string $streetAddress = null) |
|
434
|
|
|
{ |
|
435
|
18 |
|
$new = clone $this; |
|
436
|
18 |
|
$new->streetAddress = $streetAddress; |
|
437
|
|
|
|
|
438
|
18 |
|
return $new; |
|
439
|
|
|
} |
|
440
|
|
|
|
|
441
|
|
|
/** |
|
442
|
|
|
* @return null|string |
|
443
|
|
|
*/ |
|
444
|
1 |
|
public function getSubpremise() |
|
445
|
|
|
{ |
|
446
|
1 |
|
return $this->subpremise; |
|
447
|
|
|
} |
|
448
|
|
|
|
|
449
|
|
|
/** |
|
450
|
|
|
* @param string|null $subpremise |
|
451
|
|
|
* |
|
452
|
|
|
* @return GoogleAddress |
|
453
|
|
|
*/ |
|
454
|
18 |
|
public function withSubpremise(string $subpremise = null) |
|
455
|
|
|
{ |
|
456
|
18 |
|
$new = clone $this; |
|
457
|
18 |
|
$new->subpremise = $subpremise; |
|
458
|
|
|
|
|
459
|
18 |
|
return $new; |
|
460
|
|
|
} |
|
461
|
|
|
|
|
462
|
|
|
/** |
|
463
|
|
|
* @return null|string |
|
464
|
|
|
*/ |
|
465
|
|
|
public function getWard() |
|
466
|
|
|
{ |
|
467
|
|
|
return $this->ward; |
|
468
|
|
|
} |
|
469
|
|
|
|
|
470
|
|
|
/** |
|
471
|
|
|
* @param string|null $ward |
|
472
|
|
|
* |
|
473
|
|
|
* @return GoogleAddress |
|
474
|
|
|
*/ |
|
475
|
18 |
|
public function withWard(string $ward = null) |
|
476
|
|
|
{ |
|
477
|
18 |
|
$new = clone $this; |
|
478
|
18 |
|
$new->ward = $ward; |
|
479
|
|
|
|
|
480
|
18 |
|
return $new; |
|
481
|
|
|
} |
|
482
|
|
|
|
|
483
|
|
|
/** |
|
484
|
|
|
* @return null|string |
|
485
|
|
|
*/ |
|
486
|
1 |
|
public function getEstablishment() |
|
487
|
|
|
{ |
|
488
|
1 |
|
return $this->establishment; |
|
489
|
|
|
} |
|
490
|
|
|
|
|
491
|
|
|
/** |
|
492
|
|
|
* @param string|null $establishment |
|
493
|
|
|
* |
|
494
|
|
|
* @return GoogleAddress |
|
495
|
|
|
*/ |
|
496
|
18 |
|
public function withEstablishment(string $establishment = null) |
|
497
|
|
|
{ |
|
498
|
18 |
|
$new = clone $this; |
|
499
|
18 |
|
$new->establishment = $establishment; |
|
500
|
|
|
|
|
501
|
18 |
|
return $new; |
|
502
|
|
|
} |
|
503
|
|
|
|
|
504
|
|
|
/** |
|
505
|
|
|
* @return AdminLevelCollection |
|
506
|
|
|
*/ |
|
507
|
1 |
|
public function getSubLocalityLevels() |
|
508
|
|
|
{ |
|
509
|
1 |
|
return $this->subLocalityLevels; |
|
510
|
|
|
} |
|
511
|
|
|
|
|
512
|
|
|
/** |
|
513
|
|
|
* @param array $subLocalityLevel |
|
514
|
|
|
* |
|
515
|
|
|
* @return $this |
|
516
|
|
|
*/ |
|
517
|
18 |
|
public function withSubLocalityLevels(array $subLocalityLevel) |
|
518
|
|
|
{ |
|
519
|
18 |
|
$subLocalityLevels = []; |
|
520
|
18 |
|
foreach ($subLocalityLevel as $level) { |
|
521
|
3 |
|
if (empty($level['level'])) { |
|
522
|
|
|
continue; |
|
523
|
|
|
} |
|
524
|
|
|
|
|
525
|
3 |
|
$name = $level['name'] ?? $level['code'] ?? ''; |
|
526
|
3 |
|
if (empty($name)) { |
|
527
|
|
|
continue; |
|
528
|
|
|
} |
|
529
|
|
|
|
|
530
|
3 |
|
$subLocalityLevels[] = new AdminLevel($level['level'], $name, $level['code'] ?? null); |
|
531
|
|
|
} |
|
532
|
|
|
|
|
533
|
18 |
|
$subLocalityLevels = array_unique($subLocalityLevels); |
|
534
|
|
|
|
|
535
|
18 |
|
$new = clone $this; |
|
536
|
18 |
|
$new->subLocalityLevels = new AdminLevelCollection($subLocalityLevels); |
|
537
|
|
|
|
|
538
|
18 |
|
return $new; |
|
539
|
|
|
} |
|
540
|
|
|
|
|
541
|
|
|
/** |
|
542
|
|
|
* @return bool |
|
543
|
|
|
*/ |
|
544
|
16 |
|
public function isPartialMatch() |
|
545
|
|
|
{ |
|
546
|
16 |
|
return $this->partialMatch; |
|
547
|
|
|
} |
|
548
|
|
|
|
|
549
|
|
|
/** |
|
550
|
|
|
* @param bool $partialMatch |
|
551
|
|
|
* |
|
552
|
|
|
* @return $this |
|
553
|
|
|
*/ |
|
554
|
18 |
|
public function withPartialMatch(bool $partialMatch) |
|
555
|
|
|
{ |
|
556
|
18 |
|
$new = clone $this; |
|
557
|
18 |
|
$new->partialMatch = $partialMatch; |
|
558
|
|
|
|
|
559
|
18 |
|
return $new; |
|
560
|
|
|
} |
|
561
|
|
|
} |
|
562
|
|
|
|