You are here

protected function Local::getReader in GeoIP API 8.2

Get a dataset reader.

Return value

\GeoIp2\Database\Reader|null Reader that can parse Mindmax datasets.

1 call to Local::getReader()
Local::geolocate in src/Plugin/GeoLocator/Local.php
Performs geolocation on an address.

File

src/Plugin/GeoLocator/Local.php, line 67

Class

Local
Local geolocation provider.

Namespace

Drupal\geoip\Plugin\GeoLocator

Code

protected function getReader() {
  $city_uri = $this
    ->getScheme() . '://GeoLite2-City.mmdb';
  $country_uri = $this
    ->getScheme() . '://GeoLite2-Country.mmdb';
  if (file_exists($city_uri)) {
    $reader = new Reader($city_uri);
  }
  elseif (file_exists($country_uri)) {
    $reader = new Reader($country_uri);
  }
  else {

    // No dataset is installed.
    return NULL;
  }
  return $reader;
}