|
1
|
|
|
<?php |
|
2
|
|
|
namespace Kerox\Messenger\Model\Common; |
|
3
|
|
|
|
|
4
|
|
|
class Address implements \JsonSerializable |
|
5
|
|
|
{ |
|
6
|
|
|
|
|
7
|
|
|
/** |
|
8
|
|
|
* @var null|string |
|
9
|
|
|
*/ |
|
10
|
|
|
protected $name; |
|
11
|
|
|
|
|
12
|
|
|
/** |
|
13
|
|
|
* @var string |
|
14
|
|
|
*/ |
|
15
|
|
|
protected $street; |
|
16
|
|
|
|
|
17
|
|
|
/** |
|
18
|
|
|
* @var null|string |
|
19
|
|
|
*/ |
|
20
|
|
|
protected $additionalStreet; |
|
21
|
|
|
|
|
22
|
|
|
/** |
|
23
|
|
|
* @var string |
|
24
|
|
|
*/ |
|
25
|
|
|
protected $city; |
|
26
|
|
|
|
|
27
|
|
|
/** |
|
28
|
|
|
* @var string |
|
29
|
|
|
*/ |
|
30
|
|
|
protected $postalCode; |
|
31
|
|
|
|
|
32
|
|
|
/** |
|
33
|
|
|
* @var string |
|
34
|
|
|
*/ |
|
35
|
|
|
protected $state; |
|
36
|
|
|
|
|
37
|
|
|
/** |
|
38
|
|
|
* @var string |
|
39
|
|
|
*/ |
|
40
|
|
|
protected $country; |
|
41
|
|
|
|
|
42
|
|
|
/** |
|
43
|
|
|
* @var null|int |
|
44
|
|
|
*/ |
|
45
|
|
|
protected $id; |
|
46
|
|
|
|
|
47
|
|
|
/** |
|
48
|
|
|
* Address constructor. |
|
49
|
|
|
* |
|
50
|
|
|
* @param string $street |
|
51
|
|
|
* @param string $city |
|
52
|
|
|
* @param string $postalCode |
|
53
|
|
|
* @param string $state |
|
54
|
|
|
* @param string $country |
|
55
|
|
|
*/ |
|
56
|
17 |
|
public function __construct( |
|
57
|
|
|
string $street, |
|
58
|
|
|
string $city, |
|
59
|
|
|
string $postalCode, |
|
60
|
|
|
string $state, |
|
61
|
|
|
string $country |
|
62
|
|
|
) { |
|
63
|
17 |
|
$this->street = $street; |
|
64
|
17 |
|
$this->city = $city; |
|
65
|
17 |
|
$this->postalCode = $postalCode; |
|
66
|
17 |
|
$this->state = $state; |
|
67
|
17 |
|
$this->country = $country; |
|
68
|
17 |
|
} |
|
69
|
|
|
|
|
70
|
|
|
/** |
|
71
|
|
|
* @param string $name |
|
72
|
|
|
* @return \Kerox\Messenger\Model\Common\Address |
|
73
|
|
|
*/ |
|
74
|
4 |
|
public function setName(string $name): Address |
|
75
|
|
|
{ |
|
76
|
4 |
|
$this->name = $name; |
|
77
|
|
|
|
|
78
|
4 |
|
return $this; |
|
79
|
|
|
} |
|
80
|
|
|
|
|
81
|
|
|
/** |
|
82
|
|
|
* @return null|string |
|
83
|
|
|
*/ |
|
84
|
1 |
|
public function getName() |
|
85
|
|
|
{ |
|
86
|
1 |
|
return $this->name; |
|
87
|
|
|
} |
|
88
|
|
|
|
|
89
|
|
|
/** |
|
90
|
|
|
* @return string |
|
91
|
|
|
*/ |
|
92
|
3 |
|
public function getStreet(): string |
|
93
|
|
|
{ |
|
94
|
3 |
|
return $this->street; |
|
95
|
|
|
} |
|
96
|
|
|
|
|
97
|
|
|
/** |
|
98
|
|
|
* @param string $additionalStreet |
|
99
|
|
|
* @return Address |
|
100
|
|
|
*/ |
|
101
|
14 |
|
public function setAdditionalStreet(string $additionalStreet): Address |
|
102
|
|
|
{ |
|
103
|
14 |
|
$this->additionalStreet = $additionalStreet; |
|
104
|
|
|
|
|
105
|
14 |
|
return $this; |
|
106
|
|
|
} |
|
107
|
|
|
|
|
108
|
|
|
/** |
|
109
|
|
|
* @return null|string |
|
110
|
|
|
*/ |
|
111
|
3 |
|
public function getAdditionalStreet() |
|
112
|
|
|
{ |
|
113
|
3 |
|
return $this->additionalStreet; |
|
114
|
|
|
} |
|
115
|
|
|
|
|
116
|
|
|
/** |
|
117
|
|
|
* @return string |
|
118
|
|
|
*/ |
|
119
|
3 |
|
public function getCity(): string |
|
120
|
|
|
{ |
|
121
|
3 |
|
return $this->city; |
|
122
|
|
|
} |
|
123
|
|
|
|
|
124
|
|
|
/** |
|
125
|
|
|
* @return string |
|
126
|
|
|
*/ |
|
127
|
3 |
|
public function getPostalCode(): string |
|
128
|
|
|
{ |
|
129
|
3 |
|
return $this->postalCode; |
|
130
|
|
|
} |
|
131
|
|
|
|
|
132
|
|
|
/** |
|
133
|
|
|
* @return string |
|
134
|
|
|
*/ |
|
135
|
3 |
|
public function getState(): string |
|
136
|
|
|
{ |
|
137
|
3 |
|
return $this->state; |
|
138
|
|
|
} |
|
139
|
|
|
|
|
140
|
|
|
/** |
|
141
|
|
|
* @return string |
|
142
|
|
|
*/ |
|
143
|
3 |
|
public function getCountry(): string |
|
144
|
|
|
{ |
|
145
|
3 |
|
return $this->country; |
|
146
|
|
|
} |
|
147
|
|
|
|
|
148
|
|
|
/** |
|
149
|
|
|
* @param int $id |
|
150
|
|
|
* @return Address |
|
151
|
|
|
*/ |
|
152
|
3 |
|
public function setId(int $id) |
|
153
|
|
|
{ |
|
154
|
3 |
|
$this->id = $id; |
|
155
|
|
|
|
|
156
|
3 |
|
return $this; |
|
157
|
|
|
} |
|
158
|
|
|
|
|
159
|
|
|
/** |
|
160
|
|
|
* @return null|int |
|
161
|
|
|
*/ |
|
162
|
1 |
|
public function getId() |
|
163
|
|
|
{ |
|
164
|
1 |
|
return $this->id; |
|
165
|
|
|
} |
|
166
|
|
|
|
|
167
|
|
|
/** |
|
168
|
|
|
* @return array |
|
169
|
|
|
*/ |
|
170
|
5 |
|
public function jsonSerialize(): array |
|
171
|
|
|
{ |
|
172
|
|
|
$json = [ |
|
173
|
5 |
|
'name' => $this->name, |
|
174
|
5 |
|
'street_1' => $this->street, |
|
175
|
5 |
|
'street_2' => $this->additionalStreet, |
|
176
|
5 |
|
'city' => $this->city, |
|
177
|
5 |
|
'postal_code' => $this->postalCode, |
|
178
|
5 |
|
'state' => $this->state, |
|
179
|
5 |
|
'country' => $this->country, |
|
180
|
5 |
|
'id' => $this->id, |
|
181
|
|
|
]; |
|
182
|
|
|
|
|
183
|
5 |
|
return array_filter($json); |
|
184
|
|
|
} |
|
185
|
|
|
|
|
186
|
|
|
/** |
|
187
|
|
|
* @param array $payload |
|
188
|
|
|
* @return static |
|
189
|
|
|
*/ |
|
190
|
12 |
|
public static function create(array $payload) |
|
191
|
|
|
{ |
|
192
|
12 |
|
$address = new static($payload['street_1'], $payload['city'], $payload['postal_code'], $payload['state'], $payload['country']); |
|
193
|
|
|
|
|
194
|
12 |
|
if (isset($payload['street_2'])) { |
|
195
|
12 |
|
$address->setAdditionalStreet($payload['street_2']); |
|
196
|
|
|
} |
|
197
|
|
|
|
|
198
|
12 |
|
if (isset($payload['id'])) { |
|
199
|
3 |
|
$address->setId($payload['id']); |
|
200
|
|
|
} |
|
201
|
|
|
|
|
202
|
12 |
|
if (isset($payload['name'])) { |
|
203
|
4 |
|
$address->setName($payload['name']); |
|
204
|
|
|
} |
|
205
|
|
|
|
|
206
|
12 |
|
return $address; |
|
207
|
|
|
} |
|
208
|
|
|
} |
|
209
|
|
|
|