1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace LeKoala\GeoTools\Models; |
4
|
|
|
|
5
|
|
|
use LeKoala\GeoTools\Models\Country; |
6
|
|
|
use LeKoala\GeoTools\Models\Coordinates; |
7
|
|
|
|
8
|
|
|
/** |
9
|
|
|
* A global address model |
10
|
|
|
*/ |
11
|
|
|
class Address |
12
|
|
|
{ |
13
|
|
|
/** |
14
|
|
|
* @var string |
15
|
|
|
*/ |
16
|
|
|
protected $streetName; |
17
|
|
|
/** |
18
|
|
|
* @var string |
19
|
|
|
*/ |
20
|
|
|
protected $streetNumber; |
21
|
|
|
/** |
22
|
|
|
* @var string |
23
|
|
|
*/ |
24
|
|
|
protected $postalCode; |
25
|
|
|
/** |
26
|
|
|
* @var string |
27
|
|
|
*/ |
28
|
|
|
protected $locality; |
29
|
|
|
/** |
30
|
|
|
* @var Country |
31
|
|
|
*/ |
32
|
|
|
protected $country; |
33
|
|
|
/** |
34
|
|
|
* @var Coordinates |
35
|
|
|
*/ |
36
|
|
|
protected $coordinates; |
37
|
|
|
|
38
|
|
|
/** |
39
|
|
|
* @param array<string,string>|string $address |
40
|
|
|
* @param array<string,string>|string|Country $country |
41
|
|
|
* @param array<string,string>|string|Coordinates $coordinates |
42
|
|
|
*/ |
43
|
|
|
public function __construct($address = null, $country = null, $coordinates = null) |
44
|
|
|
{ |
45
|
|
|
if ($address !== null) { |
46
|
|
|
if (is_array($address)) { |
47
|
|
|
foreach ($address as $k => $v) { |
48
|
|
|
if (property_exists($this, $k)) { |
49
|
|
|
$this->$k = $v; |
50
|
|
|
} |
51
|
|
|
} |
52
|
|
|
} else { |
53
|
|
|
// TODO: parse string address |
54
|
|
|
} |
55
|
|
|
} |
56
|
|
|
|
57
|
|
|
if ($country !== null) { |
58
|
|
|
if (!$country instanceof Country) { |
59
|
|
|
$country = Country::create($country); |
60
|
|
|
} |
61
|
|
|
$this->country = $country; |
62
|
|
|
} else { |
63
|
|
|
$this->country = new Country; |
64
|
|
|
} |
65
|
|
|
|
66
|
|
|
if ($coordinates !== null) { |
67
|
|
|
if (!$coordinates instanceof Coordinates) { |
68
|
|
|
$coordinates = Coordinates::create($coordinates); |
69
|
|
|
} |
70
|
|
|
$this->coordinates = $coordinates; |
71
|
|
|
} else { |
72
|
|
|
$this->coordinates = new Coordinates; |
73
|
|
|
} |
74
|
|
|
} |
75
|
|
|
|
76
|
|
|
|
77
|
|
|
/** |
78
|
|
|
* Get the value of country |
79
|
|
|
* |
80
|
|
|
* @return Country |
81
|
|
|
*/ |
82
|
|
|
public function getCountry(): Country |
83
|
|
|
{ |
84
|
|
|
return $this->country; |
85
|
|
|
} |
86
|
|
|
|
87
|
|
|
/** |
88
|
|
|
* Set the value of country |
89
|
|
|
* |
90
|
|
|
* @param Country $country |
91
|
|
|
* @return $this |
92
|
|
|
*/ |
93
|
|
|
public function setCountry(Country $country) |
94
|
|
|
{ |
95
|
|
|
$this->country = $country; |
96
|
|
|
return $this; |
97
|
|
|
} |
98
|
|
|
|
99
|
|
|
/** |
100
|
|
|
* Get the value of coordinates |
101
|
|
|
* |
102
|
|
|
* @return Coordinates |
103
|
|
|
*/ |
104
|
|
|
public function getCoordinates(): Coordinates |
105
|
|
|
{ |
106
|
|
|
return $this->coordinates; |
107
|
|
|
} |
108
|
|
|
|
109
|
|
|
/** |
110
|
|
|
* Set the value of coordinates |
111
|
|
|
* |
112
|
|
|
* @param Coordinates $coordinates |
113
|
|
|
* @return $this |
114
|
|
|
*/ |
115
|
|
|
public function setCoordinates(Coordinates $coordinates) |
116
|
|
|
{ |
117
|
|
|
$this->coordinates = $coordinates; |
118
|
|
|
return $this; |
119
|
|
|
} |
120
|
|
|
|
121
|
|
|
/** |
122
|
|
|
* Get the value of streetName |
123
|
|
|
* |
124
|
|
|
* @return string |
125
|
|
|
*/ |
126
|
|
|
public function getStreetName(): ?string |
127
|
|
|
{ |
128
|
|
|
return $this->streetName; |
129
|
|
|
} |
130
|
|
|
|
131
|
|
|
/** |
132
|
|
|
* Set the value of streetName |
133
|
|
|
* |
134
|
|
|
* @param string $streetName |
135
|
|
|
* @return $this |
136
|
|
|
*/ |
137
|
|
|
public function setStreetName(string $streetName) |
138
|
|
|
{ |
139
|
|
|
$this->streetName = $streetName; |
140
|
|
|
return $this; |
141
|
|
|
} |
142
|
|
|
|
143
|
|
|
/** |
144
|
|
|
* Get the value of streetNumber |
145
|
|
|
* |
146
|
|
|
* @return string |
147
|
|
|
*/ |
148
|
|
|
public function getStreetNumber(): ?string |
149
|
|
|
{ |
150
|
|
|
return $this->streetNumber; |
151
|
|
|
} |
152
|
|
|
|
153
|
|
|
/** |
154
|
|
|
* Set the value of streetNumber |
155
|
|
|
* |
156
|
|
|
* @param string $streetNumber |
157
|
|
|
* @return $this |
158
|
|
|
*/ |
159
|
|
|
public function setStreetNumber(string $streetNumber) |
160
|
|
|
{ |
161
|
|
|
$this->streetNumber = $streetNumber; |
162
|
|
|
return $this; |
163
|
|
|
} |
164
|
|
|
|
165
|
|
|
/** |
166
|
|
|
* Get the value of postalCode |
167
|
|
|
* |
168
|
|
|
* @return string |
169
|
|
|
*/ |
170
|
|
|
public function getPostalCode(): ?string |
171
|
|
|
{ |
172
|
|
|
return $this->postalCode; |
173
|
|
|
} |
174
|
|
|
|
175
|
|
|
/** |
176
|
|
|
* Set the value of postalCode |
177
|
|
|
* |
178
|
|
|
* @param string $postalCode |
179
|
|
|
* @return $this |
180
|
|
|
*/ |
181
|
|
|
public function setPostalCode(string $postalCode) |
182
|
|
|
{ |
183
|
|
|
$this->postalCode = $postalCode; |
184
|
|
|
return $this; |
185
|
|
|
} |
186
|
|
|
|
187
|
|
|
/** |
188
|
|
|
* Get the value of locality |
189
|
|
|
* |
190
|
|
|
* @return string |
191
|
|
|
*/ |
192
|
|
|
public function getLocality(): ?string |
193
|
|
|
{ |
194
|
|
|
return $this->locality; |
195
|
|
|
} |
196
|
|
|
|
197
|
|
|
/** |
198
|
|
|
* Set the value of locality |
199
|
|
|
* |
200
|
|
|
* @param string $locality |
201
|
|
|
* @return $this |
202
|
|
|
*/ |
203
|
|
|
public function setLocality(string $locality) |
204
|
|
|
{ |
205
|
|
|
$this->locality = $locality; |
206
|
|
|
return $this; |
207
|
|
|
} |
208
|
|
|
} |
209
|
|
|
|