|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Spatie\BpostAddressWebservice; |
|
4
|
|
|
|
|
5
|
|
|
class Address |
|
6
|
|
|
{ |
|
7
|
|
|
/** @var string */ |
|
8
|
|
|
public $streetName; |
|
9
|
|
|
|
|
10
|
|
|
/** @var string */ |
|
11
|
|
|
public $streetNumber; |
|
12
|
|
|
|
|
13
|
|
|
/** @var string */ |
|
14
|
|
|
public $boxNumber; |
|
15
|
|
|
|
|
16
|
|
|
/** @var string */ |
|
17
|
|
|
public $postalCode; |
|
18
|
|
|
|
|
19
|
|
|
/** @var string */ |
|
20
|
|
|
public $municipalityName; |
|
21
|
|
|
|
|
22
|
|
|
/** @var string */ |
|
23
|
|
|
public $country = 'BELGIE'; |
|
24
|
|
|
|
|
25
|
|
|
protected function __construct(array $attributes) |
|
26
|
|
|
{ |
|
27
|
|
|
foreach ($attributes as $attribute => $value) { |
|
28
|
|
|
if (property_exists($this, $attribute)) { |
|
29
|
|
|
$this->$attribute = $value; |
|
30
|
|
|
} |
|
31
|
|
|
} |
|
32
|
|
|
} |
|
33
|
|
|
|
|
34
|
|
|
public static function create(array $attributes): Address |
|
35
|
|
|
{ |
|
36
|
|
|
return new static($attributes); |
|
37
|
|
|
} |
|
38
|
|
|
|
|
39
|
|
|
public static function fromResponse(array $attributes): Address |
|
40
|
|
|
{ |
|
41
|
|
|
return new static([ |
|
42
|
|
|
'streetName' => $attributes['PostalAddress']['StructuredDeliveryPointLocation']['StreetName'] ?? '', |
|
43
|
|
|
'streetNumber' => $attributes['PostalAddress']['StructuredDeliveryPointLocation']['StreetNumber'] ?? '', |
|
44
|
|
|
'boxNumber' => $attributes['PostalAddress']['StructuredDeliveryPointLocation']['BoxNumber'] ?? '', |
|
45
|
|
|
'postalCode' => $attributes['PostalAddress']['StructuredPostalCodeMunicipality']['PostalCode'] ?? '', |
|
46
|
|
|
'municipalityName' => $attributes['PostalAddress']['StructuredPostalCodeMunicipality']['MunicipalityName'] ?? '', |
|
47
|
|
|
'country' => $attributes['PostalAddress']['CountryName'] ?? '', |
|
48
|
|
|
]); |
|
49
|
|
|
} |
|
50
|
|
|
|
|
51
|
|
|
public function toArray(): array |
|
52
|
|
|
{ |
|
53
|
|
|
return [ |
|
54
|
|
|
'streetName' => $this->streetName, |
|
55
|
|
|
'streetNumber' => $this->streetNumber, |
|
56
|
|
|
'boxNumber' => $this->boxNumber, |
|
57
|
|
|
'postalCode' => $this->postalCode, |
|
58
|
|
|
'municipalityName' => $this->municipalityName, |
|
59
|
|
|
'country' => $this->country, |
|
60
|
|
|
]; |
|
61
|
|
|
} |
|
62
|
|
|
} |
|
63
|
|
|
|