mirror of
https://github.com/shlinkio/shlink.git
synced 2025-02-18 16:29:56 +03:00
Fixed region resolved in GeoLite2
This commit is contained in:
parent
0e3a0a1eec
commit
9a0f9207be
2 changed files with 9 additions and 3 deletions
|
@ -48,6 +48,7 @@
|
||||||
"zendframework/zend-stdlib": "^3.0"
|
"zendframework/zend-stdlib": "^3.0"
|
||||||
},
|
},
|
||||||
"require-dev": {
|
"require-dev": {
|
||||||
|
"devster/ubench": "^2.0",
|
||||||
"filp/whoops": "^2.0",
|
"filp/whoops": "^2.0",
|
||||||
"infection/infection": "^0.11.0",
|
"infection/infection": "^0.11.0",
|
||||||
"phpstan/phpstan": "^0.10.0",
|
"phpstan/phpstan": "^0.10.0",
|
||||||
|
|
|
@ -6,8 +6,10 @@ namespace Shlinkio\Shlink\Common\IpGeolocation;
|
||||||
use GeoIp2\Database\Reader;
|
use GeoIp2\Database\Reader;
|
||||||
use GeoIp2\Exception\AddressNotFoundException;
|
use GeoIp2\Exception\AddressNotFoundException;
|
||||||
use GeoIp2\Model\City;
|
use GeoIp2\Model\City;
|
||||||
|
use GeoIp2\Record\Subdivision;
|
||||||
use MaxMind\Db\Reader\InvalidDatabaseException;
|
use MaxMind\Db\Reader\InvalidDatabaseException;
|
||||||
use Shlinkio\Shlink\Common\Exception\WrongIpException;
|
use Shlinkio\Shlink\Common\Exception\WrongIpException;
|
||||||
|
use function Functional\first;
|
||||||
|
|
||||||
class GeoLite2LocationResolver implements IpLocationResolverInterface
|
class GeoLite2LocationResolver implements IpLocationResolverInterface
|
||||||
{
|
{
|
||||||
|
@ -40,13 +42,16 @@ class GeoLite2LocationResolver implements IpLocationResolverInterface
|
||||||
|
|
||||||
private function mapFields(City $city): array
|
private function mapFields(City $city): array
|
||||||
{
|
{
|
||||||
|
/** @var Subdivision $region */
|
||||||
|
$region = first($city->subdivisions);
|
||||||
|
|
||||||
return [
|
return [
|
||||||
'country_code' => $city->country->isoCode ?? '',
|
'country_code' => $city->country->isoCode ?? '',
|
||||||
'country_name' => $city->country->name ?? '',
|
'country_name' => $city->country->name ?? '',
|
||||||
'region_name' => $city->mostSpecificSubdivision->name ?? '',
|
'region_name' => $region->name ?? '',
|
||||||
'city' => $city->city->name ?? '',
|
'city' => $city->city->name ?? '',
|
||||||
'latitude' => (string) $city->location->latitude, // FIXME Cast to string for BC compatibility
|
'latitude' => $city->location->latitude ?? '',
|
||||||
'longitude' => (string) $city->location->longitude, // FIXME Cast to string for BC compatibility
|
'longitude' => $city->location->longitude ?? '',
|
||||||
'time_zone' => $city->location->timeZone ?? '',
|
'time_zone' => $city->location->timeZone ?? '',
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue