|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
namespace Appwilio\RussianPostSDK\Dispatching\Entities; |
|
6
|
|
|
|
|
7
|
|
|
use Appwilio\RussianPostSDK\Dispatching\Instantiator; |
|
8
|
|
|
use Appwilio\RussianPostSDK\Dispatching\Enum\AddressType; |
|
9
|
|
|
use Appwilio\RussianPostSDK\Dispatching\Contracts\Arrayable; |
|
10
|
|
|
use Appwilio\RussianPostSDK\Dispatching\Endpoints\Services\Entities\NormalizedAddress; |
|
11
|
|
|
|
|
12
|
|
|
final class Address extends AbstractAddress implements Arrayable |
|
13
|
|
|
{ |
|
14
|
|
|
public static function fromNormalizedAddress(NormalizedAddress $address): self |
|
15
|
|
|
{ |
|
16
|
|
|
if ($address->isUnuseful()) { |
|
17
|
|
|
throw new \InvalidArgumentException('У нормализованного адреса неприемлемое качество.'); |
|
18
|
|
|
} |
|
19
|
|
|
|
|
20
|
|
|
return Instantiator::instantiateFrom(self::class, $address, [ |
|
21
|
|
|
'id', 'original-address', 'quality-code', 'validation-code' |
|
22
|
|
|
]); |
|
23
|
|
|
} |
|
24
|
|
|
|
|
25
|
|
|
public function __construct(?string $addressType = null) |
|
26
|
|
|
{ |
|
27
|
|
|
$this->setType($addressType ?? AddressType::DEFAULT); |
|
28
|
|
|
} |
|
29
|
|
|
|
|
30
|
|
|
public function setType(string $addressType) |
|
31
|
|
|
{ |
|
32
|
|
|
$this->data['address-type'] = $addressType; |
|
33
|
|
|
|
|
34
|
|
|
return $this; |
|
35
|
|
|
} |
|
36
|
|
|
|
|
37
|
|
|
public function getAddressType(): string |
|
38
|
|
|
{ |
|
39
|
|
|
return $this->get('address-type'); |
|
40
|
|
|
} |
|
41
|
|
|
|
|
42
|
|
|
public function getCountryCode(): ?string |
|
43
|
|
|
{ |
|
44
|
|
|
return $this->get('mail-direct'); |
|
45
|
|
|
} |
|
46
|
|
|
|
|
47
|
|
|
public function setCountryCode(int $countryCode) |
|
48
|
|
|
{ |
|
49
|
|
|
$this->data['mail-direct'] = $countryCode; |
|
50
|
|
|
|
|
51
|
|
|
return $this; |
|
52
|
|
|
} |
|
53
|
|
|
|
|
54
|
|
|
public function setIndex(string $index) |
|
55
|
|
|
{ |
|
56
|
|
|
$this->data['index'] = $index; |
|
57
|
|
|
|
|
58
|
|
|
return $this; |
|
59
|
|
|
} |
|
60
|
|
|
|
|
61
|
|
|
public function setArea(string $area) |
|
62
|
|
|
{ |
|
63
|
|
|
$this->data['area'] = $area; |
|
64
|
|
|
|
|
65
|
|
|
return $this; |
|
66
|
|
|
} |
|
67
|
|
|
|
|
68
|
|
|
public function setPlace(string $place) |
|
69
|
|
|
{ |
|
70
|
|
|
$this->data['place'] = $place; |
|
71
|
|
|
|
|
72
|
|
|
return $this; |
|
73
|
|
|
} |
|
74
|
|
|
|
|
75
|
|
|
public function setRegion(string $region) |
|
76
|
|
|
{ |
|
77
|
|
|
$this->data['region'] = $region; |
|
78
|
|
|
|
|
79
|
|
|
return $this; |
|
80
|
|
|
} |
|
81
|
|
|
|
|
82
|
|
|
public function setLocation(string $location) |
|
83
|
|
|
{ |
|
84
|
|
|
$this->data['location'] = $location; |
|
85
|
|
|
|
|
86
|
|
|
return $this; |
|
87
|
|
|
} |
|
88
|
|
|
|
|
89
|
|
|
public function setStreet(string $street) |
|
90
|
|
|
{ |
|
91
|
|
|
$this->data['street'] = $street; |
|
92
|
|
|
|
|
93
|
|
|
return $this; |
|
94
|
|
|
} |
|
95
|
|
|
|
|
96
|
|
|
public function setHouse(string $house) |
|
97
|
|
|
{ |
|
98
|
|
|
$this->data['house'] = $house; |
|
99
|
|
|
|
|
100
|
|
|
return $this; |
|
101
|
|
|
} |
|
102
|
|
|
|
|
103
|
|
|
public function setRoom(string $room) |
|
104
|
|
|
{ |
|
105
|
|
|
$this->data['room'] = $room; |
|
106
|
|
|
|
|
107
|
|
|
return $this; |
|
108
|
|
|
} |
|
109
|
|
|
|
|
110
|
|
|
public function setSlash(string $slash) |
|
111
|
|
|
{ |
|
112
|
|
|
$this->data['slash'] = $slash; |
|
113
|
|
|
|
|
114
|
|
|
return $this; |
|
115
|
|
|
} |
|
116
|
|
|
|
|
117
|
|
|
public function setBuilding(string $building) |
|
118
|
|
|
{ |
|
119
|
|
|
$this->data['building'] = $building; |
|
120
|
|
|
|
|
121
|
|
|
return $this; |
|
122
|
|
|
} |
|
123
|
|
|
|
|
124
|
|
|
public function setCorpus(string $corpus) |
|
125
|
|
|
{ |
|
126
|
|
|
$this->data['corpus'] = $corpus; |
|
127
|
|
|
|
|
128
|
|
|
return $this; |
|
129
|
|
|
} |
|
130
|
|
|
|
|
131
|
|
|
public function setLetter(string $letter) |
|
132
|
|
|
{ |
|
133
|
|
|
$this->data['letter'] = $letter; |
|
134
|
|
|
|
|
135
|
|
|
return $this; |
|
136
|
|
|
} |
|
137
|
|
|
|
|
138
|
|
|
public function setHotel(string $hotel) |
|
139
|
|
|
{ |
|
140
|
|
|
$this->data['hotel'] = $hotel; |
|
141
|
|
|
|
|
142
|
|
|
return $this; |
|
143
|
|
|
} |
|
144
|
|
|
|
|
145
|
|
|
public function getVladenie(): ?string |
|
146
|
|
|
{ |
|
147
|
|
|
return $this->get('vladenie'); |
|
148
|
|
|
} |
|
149
|
|
|
|
|
150
|
|
|
public function setVladenie(string $vladenie) |
|
151
|
|
|
{ |
|
152
|
|
|
$this->data['vladenie'] = $vladenie; |
|
153
|
|
|
|
|
154
|
|
|
return $this; |
|
155
|
|
|
} |
|
156
|
|
|
|
|
157
|
|
|
public function toArray(): array |
|
158
|
|
|
{ |
|
159
|
|
|
return $this->data; |
|
160
|
|
|
} |
|
161
|
|
|
} |
|
162
|
|
|
|