|
1
|
|
|
<?php |
|
2
|
|
|
namespace Kerox\Messenger\Model\Common; |
|
3
|
|
|
|
|
4
|
|
|
class Address implements \JsonSerializable |
|
5
|
|
|
{ |
|
6
|
|
|
|
|
7
|
|
|
/** |
|
8
|
|
|
* @var string |
|
9
|
|
|
*/ |
|
10
|
|
|
protected $street; |
|
11
|
|
|
|
|
12
|
|
|
/** |
|
13
|
|
|
* @var null|string |
|
14
|
|
|
*/ |
|
15
|
|
|
protected $additionalStreet; |
|
16
|
|
|
|
|
17
|
|
|
/** |
|
18
|
|
|
* @var string |
|
19
|
|
|
*/ |
|
20
|
|
|
protected $city; |
|
21
|
|
|
|
|
22
|
|
|
/** |
|
23
|
|
|
* @var string |
|
24
|
|
|
*/ |
|
25
|
|
|
protected $postalCode; |
|
26
|
|
|
|
|
27
|
|
|
/** |
|
28
|
|
|
* @var string |
|
29
|
|
|
*/ |
|
30
|
|
|
protected $state; |
|
31
|
|
|
|
|
32
|
|
|
/** |
|
33
|
|
|
* @var string |
|
34
|
|
|
*/ |
|
35
|
|
|
protected $country; |
|
36
|
|
|
|
|
37
|
|
|
/** |
|
38
|
|
|
* Address constructor. |
|
39
|
|
|
* |
|
40
|
|
|
* @param string $street |
|
41
|
|
|
* @param string $city |
|
42
|
|
|
* @param string $postalCode |
|
43
|
|
|
* @param string $state |
|
44
|
|
|
* @param string $country |
|
45
|
|
|
*/ |
|
46
|
5 |
|
public function __construct( |
|
47
|
|
|
string $street, |
|
48
|
|
|
string $city, |
|
49
|
|
|
string $postalCode, |
|
50
|
|
|
string $state, |
|
51
|
|
|
string $country |
|
52
|
|
|
) { |
|
53
|
5 |
|
$this->street = $street; |
|
54
|
5 |
|
$this->city = $city; |
|
55
|
5 |
|
$this->postalCode = $postalCode; |
|
56
|
5 |
|
$this->state = $state; |
|
57
|
5 |
|
$this->country = $country; |
|
58
|
5 |
|
} |
|
59
|
|
|
|
|
60
|
|
|
/** |
|
61
|
|
|
* @return string |
|
62
|
|
|
*/ |
|
63
|
1 |
|
public function getStreet(): string |
|
64
|
|
|
{ |
|
65
|
1 |
|
return $this->street; |
|
66
|
|
|
} |
|
67
|
|
|
|
|
68
|
|
|
/** |
|
69
|
|
|
* @param string $additionalStreet |
|
70
|
|
|
* @return Address |
|
71
|
|
|
*/ |
|
72
|
5 |
|
public function setAdditionalStreet(string $additionalStreet): Address |
|
73
|
|
|
{ |
|
74
|
5 |
|
$this->additionalStreet = $additionalStreet; |
|
75
|
|
|
|
|
76
|
5 |
|
return $this; |
|
77
|
|
|
} |
|
78
|
|
|
|
|
79
|
|
|
/** |
|
80
|
|
|
* @return null|string |
|
81
|
|
|
*/ |
|
82
|
1 |
|
public function getAdditionalStreet() |
|
83
|
|
|
{ |
|
84
|
1 |
|
return $this->additionalStreet; |
|
85
|
|
|
} |
|
86
|
|
|
|
|
87
|
|
|
/** |
|
88
|
|
|
* @return string |
|
89
|
|
|
*/ |
|
90
|
1 |
|
public function getCity(): string |
|
91
|
|
|
{ |
|
92
|
1 |
|
return $this->city; |
|
93
|
|
|
} |
|
94
|
|
|
|
|
95
|
|
|
/** |
|
96
|
|
|
* @return string |
|
97
|
|
|
*/ |
|
98
|
1 |
|
public function getPostalCode(): string |
|
99
|
|
|
{ |
|
100
|
1 |
|
return $this->postalCode; |
|
101
|
|
|
} |
|
102
|
|
|
|
|
103
|
|
|
/** |
|
104
|
|
|
* @return string |
|
105
|
|
|
*/ |
|
106
|
1 |
|
public function getState(): string |
|
107
|
|
|
{ |
|
108
|
1 |
|
return $this->state; |
|
109
|
|
|
} |
|
110
|
|
|
|
|
111
|
|
|
/** |
|
112
|
|
|
* @return string |
|
113
|
|
|
*/ |
|
114
|
1 |
|
public function getCountry(): string |
|
115
|
|
|
{ |
|
116
|
1 |
|
return $this->country; |
|
117
|
|
|
} |
|
118
|
|
|
|
|
119
|
|
|
/** |
|
120
|
|
|
* @return array |
|
121
|
|
|
*/ |
|
122
|
|
|
public function jsonSerialize(): array |
|
123
|
|
|
{ |
|
124
|
|
|
$json = [ |
|
125
|
|
|
'street_1' => $this->street, |
|
126
|
|
|
'street_2' => $this->additionalStreet, |
|
127
|
|
|
'city' => $this->city, |
|
128
|
|
|
'postal_code' => $this->postalCode, |
|
129
|
|
|
'state' => $this->state, |
|
130
|
|
|
'country' => $this->country, |
|
131
|
|
|
]; |
|
132
|
|
|
|
|
133
|
|
|
return array_filter($json); |
|
134
|
|
|
} |
|
135
|
|
|
|
|
136
|
|
|
/** |
|
137
|
|
|
* @param array $payload |
|
138
|
|
|
* @return static |
|
139
|
|
|
*/ |
|
140
|
5 |
|
public static function create(array $payload) |
|
141
|
|
|
{ |
|
142
|
5 |
|
$address = new static($payload['street_1'], $payload['city'], $payload['postal_code'], $payload['state'], $payload['country']); |
|
143
|
|
|
|
|
144
|
5 |
|
if (isset($payload['street_2'])) { |
|
145
|
5 |
|
$address->setAdditionalStreet($payload['street_2']); |
|
146
|
|
|
} |
|
147
|
|
|
|
|
148
|
5 |
|
return $address; |
|
149
|
|
|
} |
|
150
|
|
|
} |
|
151
|
|
|
|