mirror of
https://github.com/shlinkio/shlink.git
synced 2024-11-27 08:18:24 +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"
|
||||
},
|
||||
"require-dev": {
|
||||
"devster/ubench": "^2.0",
|
||||
"filp/whoops": "^2.0",
|
||||
"infection/infection": "^0.11.0",
|
||||
"phpstan/phpstan": "^0.10.0",
|
||||
|
|
|
@ -6,8 +6,10 @@ namespace Shlinkio\Shlink\Common\IpGeolocation;
|
|||
use GeoIp2\Database\Reader;
|
||||
use GeoIp2\Exception\AddressNotFoundException;
|
||||
use GeoIp2\Model\City;
|
||||
use GeoIp2\Record\Subdivision;
|
||||
use MaxMind\Db\Reader\InvalidDatabaseException;
|
||||
use Shlinkio\Shlink\Common\Exception\WrongIpException;
|
||||
use function Functional\first;
|
||||
|
||||
class GeoLite2LocationResolver implements IpLocationResolverInterface
|
||||
{
|
||||
|
@ -40,13 +42,16 @@ class GeoLite2LocationResolver implements IpLocationResolverInterface
|
|||
|
||||
private function mapFields(City $city): array
|
||||
{
|
||||
/** @var Subdivision $region */
|
||||
$region = first($city->subdivisions);
|
||||
|
||||
return [
|
||||
'country_code' => $city->country->isoCode ?? '',
|
||||
'country_name' => $city->country->name ?? '',
|
||||
'region_name' => $city->mostSpecificSubdivision->name ?? '',
|
||||
'region_name' => $region->name ?? '',
|
||||
'city' => $city->city->name ?? '',
|
||||
'latitude' => (string) $city->location->latitude, // FIXME Cast to string for BC compatibility
|
||||
'longitude' => (string) $city->location->longitude, // FIXME Cast to string for BC compatibility
|
||||
'latitude' => $city->location->latitude ?? '',
|
||||
'longitude' => $city->location->longitude ?? '',
|
||||
'time_zone' => $city->location->timeZone ?? '',
|
||||
];
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue