@@ -51,14 +51,9 @@ final class Address
5151 private $ postalCode ;
5252
5353 /**
54- * @var County
54+ * @var AdminLevelCollection
5555 */
56- private $ county ;
57-
58- /**
59- * @var Region
60- */
61- private $ region ;
56+ private $ adminLevels ;
6257
6358 /**
6459 * @var Country
@@ -78,17 +73,16 @@ final class Address
7873 * @param string $subLocality
7974 */
8075 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
9286 ) {
9387 $ this ->coordinates = $ coordinates ;
9488 $ this ->bounds = $ bounds ;
@@ -97,8 +91,7 @@ public function __construct(
9791 $ this ->postalCode = $ postalCode ;
9892 $ this ->locality = $ locality ;
9993 $ this ->subLocality = $ subLocality ;
100- $ this ->county = $ county ;
101- $ this ->region = $ region ;
94+ $ this ->adminLevels = $ adminLevels ?: new AdminLevelCollection ();
10295 $ this ->country = $ country ;
10396 $ this ->timezone = $ timezone ;
10497 }
@@ -203,43 +196,13 @@ public function getSubLocality()
203196 }
204197
205198 /**
206- * Returns the county value .
199+ * Returns the administrative levels .
207200 *
208- * @return County
201+ * @return AdminLevelCollection
209202 */
210- public function getCounty ()
203+ public function getAdminLevels ()
211204 {
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 ;
243206 }
244207
245208 /**
@@ -279,6 +242,14 @@ public function getTimezone()
279242 */
280243 public function toArray ()
281244 {
245+ $ adminLevels = [];
246+ foreach ($ this ->adminLevels as $ adminLevel ) {
247+ $ adminLevels [$ adminLevel ->getLevel ()] = [
248+ 'name ' => $ adminLevel ->getName (),
249+ 'code ' => $ adminLevel ->getCode ()
250+ ];
251+ }
252+
282253 return array (
283254 'latitude ' => $ this ->getLatitude (),
284255 'longitude ' => $ this ->getLongitude (),
@@ -288,10 +259,7 @@ public function toArray()
288259 'postalCode ' => $ this ->postalCode ,
289260 'locality ' => $ this ->locality ,
290261 '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 ,
295263 'country ' => $ this ->country ->getName (),
296264 'countryCode ' => $ this ->country ->getCode (),
297265 'timezone ' => $ this ->timezone ,
0 commit comments