Change the key to <addresspart_type>-ISO3166-2 to support xml response correctly

This commit is contained in:
Artem Ziablytskyi
2022-01-26 17:40:39 +01:00
committed by Sarah Hoffmann
parent 82dbcbb12a
commit 6bee188f24
3 changed files with 7 additions and 10 deletions

View File

@@ -28,7 +28,7 @@ a single place (for reverse) of the following format:
"city": "London", "city": "London",
"state_district": "Greater London", "state_district": "Greater London",
"state": "England", "state": "England",
"ISO3166-2": "GB-ENG", "state-ISO3166-2": "GB-ENG",
"postcode": "SW1A 2DU", "postcode": "SW1A 2DU",
"country": "United Kingdom", "country": "United Kingdom",
"country_code": "gb" "country_code": "gb"
@@ -181,7 +181,7 @@ Additional information requested with `addressdetails=1`, `extratags=1` and
<city>London</city> <city>London</city>
<state_district>Greater London</state_district> <state_district>Greater London</state_district>
<state>England</state> <state>England</state>
<state_code>ENG</state_code> <state-ISO3166-2>GB-ENG</state_code>
<postcode>SW1A 2DU</postcode> <postcode>SW1A 2DU</postcode>
<country>United Kingdom</country> <country>United Kingdom</country>
<country_code>gb</country_code> <country_code>gb</country_code>
@@ -282,7 +282,7 @@ with a designation label. Per default the following labels may appear:
* continent * continent
* country, country_code * country, country_code
* region, state, state_code, state_district, county * region, state, state-ISO3166-2, state_district, county, county-ISO3166-2
* municipality, city, town, village * municipality, city, town, village
* city_district, district, borough, suburb, subdivision * city_district, district, borough, suburb, subdivision
* hamlet, croft, isolated_dwelling * hamlet, croft, isolated_dwelling

View File

@@ -94,7 +94,7 @@ class AddressDetails
$aAddress[$sTypeLabel] = $sName; $aAddress[$sTypeLabel] = $sName;
if (!empty($aLine['name'])) { if (!empty($aLine['name'])) {
$this->addStateCode($aAddress, $sTypeLabel, $aLine['name']); $this->addSubdivisionCode($aAddress, $sTypeLabel, $aLine['name']);
} }
} }
} }
@@ -179,16 +179,13 @@ class AddressDetails
return $this->aAddressLines; return $this->aAddressLines;
} }
/** private function addSubdivisionCode(&$aAddress, $sTypeLabel, $nameDetails)
* Add `state_code` field to address details to represent second part of ISO 3166-2 country subdivision code
*/
private function addStateCode(&$aAddress, $sTypeLabel, $nameDetails)
{ {
if (is_string($nameDetails)) { if (is_string($nameDetails)) {
$nameDetails = json_decode('{' . str_replace('"=>"', '":"', $nameDetails) . '}', true); $nameDetails = json_decode('{' . str_replace('"=>"', '":"', $nameDetails) . '}', true);
} }
if (!empty($nameDetails['ISO3166-2'])) { if (!empty($nameDetails['ISO3166-2'])) {
$aAddress["$sTypeLabel:ISO3166-2"] = $nameDetails['ISO3166-2']; $aAddress["$sTypeLabel-ISO3166-2"] = $nameDetails['ISO3166-2'];
} }
} }
} }

View File

@@ -86,7 +86,7 @@ class AddressDetailsTest extends \PHPUnit\Framework\TestCase
'city' => 'London', 'city' => 'London',
'state_district' => 'Greater London', 'state_district' => 'Greater London',
'state' => 'England', 'state' => 'England',
'state:ISO3166-2' => 'GB-ENG', 'state-ISO3166-2' => 'GB-ENG',
'postcode' => 'SW1A 2AA', 'postcode' => 'SW1A 2AA',
'country' => 'United Kingdom', 'country' => 'United Kingdom',
'country_code' => 'gb' 'country_code' => 'gb'