Fixed GeoIP lookup causing an exception when no MMDB is available.
This commit is contained in:
parent
01b3f41742
commit
ba4f03cefa
2 changed files with 8 additions and 0 deletions
|
@ -17,6 +17,11 @@ final class GeoIP {
|
|||
return self::$geoip;
|
||||
}
|
||||
|
||||
public static function isAvailable(): bool {
|
||||
return !empty(self::$geoipDbPath)
|
||||
&& is_file(self::$geoipDbPath);
|
||||
}
|
||||
|
||||
public static function resolveCountry(string $ipAddress) {
|
||||
return self::getReader()->country($ipAddress);
|
||||
}
|
||||
|
|
|
@ -23,6 +23,9 @@ final class IPAddress {
|
|||
}
|
||||
|
||||
public static function country(string $address, string $fallback = 'XX'): string {
|
||||
if(!GeoIP::isAvailable())
|
||||
return $fallback;
|
||||
|
||||
try {
|
||||
return GeoIP::resolveCountry($address)->country->isoCode ?? $fallback;
|
||||
} catch(AddressNotFoundException $e) {
|
||||
|
|
Loading…
Reference in a new issue