@@ -51,14 +51,9 @@ final class Address
51
51
private $ postalCode ;
52
52
53
53
/**
54
- * @var County
54
+ * @var AdminLevelCollection
55
55
*/
56
- private $ county ;
57
-
58
- /**
59
- * @var Region
60
- */
61
- private $ region ;
56
+ private $ adminLevels ;
62
57
63
58
/**
64
59
* @var Country
@@ -78,17 +73,16 @@ final class Address
78
73
* @param string $subLocality
79
74
*/
80
75
public function __construct (
81
- Coordinates $ coordinates = null ,
82
- Bounds $ bounds = null ,
83
- $ streetNumber = null ,
84
- $ streetName = null ,
85
- $ postalCode = null ,
86
- $ locality = null ,
87
- $ subLocality = null ,
88
- County $ county = null ,
89
- Region $ region = null ,
90
- Country $ country = null ,
91
- $ timezone = null
76
+ Coordinates $ coordinates = null ,
77
+ Bounds $ bounds = null ,
78
+ $ streetNumber = null ,
79
+ $ streetName = null ,
80
+ $ postalCode = null ,
81
+ $ locality = null ,
82
+ $ subLocality = null ,
83
+ AdminLevelCollection $ adminLevels = null ,
84
+ Country $ country = null ,
85
+ $ timezone = null
92
86
) {
93
87
$ this ->coordinates = $ coordinates ;
94
88
$ this ->bounds = $ bounds ;
@@ -97,8 +91,7 @@ public function __construct(
97
91
$ this ->postalCode = $ postalCode ;
98
92
$ this ->locality = $ locality ;
99
93
$ this ->subLocality = $ subLocality ;
100
- $ this ->county = $ county ;
101
- $ this ->region = $ region ;
94
+ $ this ->adminLevels = $ adminLevels ?: new AdminLevelCollection ();
102
95
$ this ->country = $ country ;
103
96
$ this ->timezone = $ timezone ;
104
97
}
@@ -203,43 +196,13 @@ public function getSubLocality()
203
196
}
204
197
205
198
/**
206
- * Returns the county value .
199
+ * Returns the administrative levels .
207
200
*
208
- * @return County
201
+ * @return AdminLevelCollection
209
202
*/
210
- public function getCounty ()
203
+ public function getAdminLevels ()
211
204
{
212
- return $ this ->county ;
213
- }
214
-
215
- /**
216
- * Returns the county short name.
217
- *
218
- * @return string
219
- */
220
- public function getCountyCode ()
221
- {
222
- return $ this ->county ->getCode ();
223
- }
224
-
225
- /**
226
- * Returns the region value.
227
- *
228
- * @return Region
229
- */
230
- public function getRegion ()
231
- {
232
- return $ this ->region ;
233
- }
234
-
235
- /**
236
- * Returns the region short name.
237
- *
238
- * @return string
239
- */
240
- public function getRegionCode ()
241
- {
242
- return $ this ->region ->getCode ();
205
+ return $ this ->adminLevels ;
243
206
}
244
207
245
208
/**
@@ -279,6 +242,14 @@ public function getTimezone()
279
242
*/
280
243
public function toArray ()
281
244
{
245
+ $ adminLevels = [];
246
+ foreach ($ this ->adminLevels as $ adminLevel ) {
247
+ $ adminLevels [$ adminLevel ->getLevel ()] = [
248
+ 'name ' => $ adminLevel ->getName (),
249
+ 'code ' => $ adminLevel ->getCode ()
250
+ ];
251
+ }
252
+
282
253
return array (
283
254
'latitude ' => $ this ->getLatitude (),
284
255
'longitude ' => $ this ->getLongitude (),
@@ -288,10 +259,7 @@ public function toArray()
288
259
'postalCode ' => $ this ->postalCode ,
289
260
'locality ' => $ this ->locality ,
290
261
'subLocality ' => $ this ->subLocality ,
291
- 'county ' => $ this ->county ->getName (),
292
- 'countyCode ' => $ this ->county ->getCode (),
293
- 'region ' => $ this ->region ->getName (),
294
- 'regionCode ' => $ this ->region ->getCode (),
262
+ 'adminLevels ' => $ adminLevels ,
295
263
'country ' => $ this ->country ->getName (),
296
264
'countryCode ' => $ this ->country ->getCode (),
297
265
'timezone ' => $ this ->timezone ,
0 commit comments