You are here

public function Cdn::geolocate in GeoIP API 8.2

Performs geolocation on an address.

Parameters

string $ip_address: The IP address to geolocate.

Return value

string The geolocated country code, or NULL if not found.

Overrides GeoLocatorInterface::geolocate

File

src/Plugin/GeoLocator/Cdn.php, line 22

Class

Cdn
CDN geolocation provider.

Namespace

Drupal\geoip\Plugin\GeoLocator

Code

public function geolocate($ip_address) {
  if ($this
    ->checkCloudflare()) {
    $country_code = $this
      ->checkCloudflare();
  }
  elseif ($this
    ->checkCloudFront()) {
    $country_code = $this
      ->checkCloudFront();
  }
  elseif ($this
    ->checkCustomHeader()) {
    $country_code = $this
      ->checkCustomHeader();
  }
  else {

    // Could not geolocate based off of CDN.
    if ($this->geoIpConfig
      ->get('debug')) {
      $this->logger
        ->notice($this
        ->t('Unable to look up %ip_address via CDN header', [
        '%ip_address' => $ip_address,
      ]));
    }
    return NULL;
  }
  if ($this->geoIpConfig
    ->get('debug')) {
    $this->logger
      ->notice($this
      ->t('Discovered %ip_address via CDN header', [
      '%ip_address' => $ip_address,
    ]));
  }
  return $country_code;
}