Skip to content

Commit d0fd842

Browse files
committed
Merge branch '1.7'
2 parents c1e8a33 + ddb35bf commit d0fd842

File tree

4 files changed

+23
-7
lines changed

4 files changed

+23
-7
lines changed

src/Geocoder/Provider/AbstractProvider.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,4 +151,16 @@ protected function getLocalhostDefaults()
151151
'country' => 'localhost',
152152
);
153153
}
154+
155+
/**
156+
* @param array $results
157+
*
158+
* @return array
159+
*/
160+
protected function fixEncoding(array $results)
161+
{
162+
return array_map(function($value) {
163+
return is_string($value) ? utf8_encode($value) : $value;
164+
}, $results);
165+
}
154166
}

src/Geocoder/Provider/GeoipProvider.php

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ public function getGeocodedData($address)
5858
$timezone = @geoip_time_zone_by_country_and_region($results['country_code'], $results['region']) ?: null;
5959
$region = @geoip_region_name_by_code($results['country_code'], $results['region']) ?: $results['region'];
6060

61-
$results = array_merge($this->getDefaults(), array(
61+
return $this->fixEncoding(array_merge($this->getDefaults(), array(
6262
'latitude' => $results['latitude'],
6363
'longitude' => $results['longitude'],
6464
'city' => $results['city'],
@@ -68,11 +68,7 @@ public function getGeocodedData($address)
6868
'country' => $results['country_name'],
6969
'countryCode' => $results['country_code'],
7070
'timezone' => $timezone,
71-
));
72-
73-
return array(array_map(function($value) {
74-
return is_string($value) ? utf8_encode($value) : $value;
75-
}, $results));
71+
)));
7672
}
7773

7874
/**

src/Geocoder/Provider/MaxMindBinaryProvider.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ public function getGeocodedData($address)
7575
throw new NoResultException(sprintf('No results found for IP address %s', $address));
7676
}
7777

78-
return array(array_merge($this->getDefaults(), array(
78+
return $this->fixEncoding(array_merge($this->getDefaults(), array(
7979
'countryCode' => $geoIpRecord->country_code,
8080
'country' => $geoIpRecord->country_name,
8181
'region' => $geoIpRecord->region,

tests/Geocoder/Tests/Provider/MaxMindBinaryProviderTest.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,14 @@ public function testFindLocationByIp($ip, $expectedCity, $expectedCountry)
9292
$this->assertEquals($expectedCountry, $result['country']);
9393
}
9494

95+
public function testShouldReturnResultsAsUtf8Encoded()
96+
{
97+
$provider = new MaxMindBinaryProvider($this->binaryFile);
98+
$result = $provider->getGeocodedData('212.51.181.237');
99+
100+
$this->assertSame('Châlette-sur-loing', $result['city']);
101+
}
102+
95103
public function testGetName()
96104
{
97105
$provider = new MaxMindBinaryProvider($this->binaryFile);

0 commit comments

Comments
 (0)