class Local in GeoIP API 8.2
Local geolocation provider.
Plugin annotation
@GeoLocator(
id = "local",
label = "Local dataset",
description = "Uses local MaxmindDB dataset for geolocation",
weight = 0
)
Hierarchy
- class \Drupal\Component\Plugin\PluginBase implements DerivativeInspectionInterface, PluginInspectionInterface
- class \Drupal\Core\Plugin\PluginBase uses DependencySerializationTrait, MessengerTrait, StringTranslationTrait
- class \Drupal\geoip\Plugin\GeoLocator\GeoLocatorBase implements ContainerFactoryPluginInterface, GeoLocatorInterface
- class \Drupal\geoip\Plugin\GeoLocator\Local
- class \Drupal\geoip\Plugin\GeoLocator\GeoLocatorBase implements ContainerFactoryPluginInterface, GeoLocatorInterface
- class \Drupal\Core\Plugin\PluginBase uses DependencySerializationTrait, MessengerTrait, StringTranslationTrait
Expanded class hierarchy of Local
File
- src/
Plugin/ GeoLocator/ Local.php, line 19
Namespace
Drupal\geoip\Plugin\GeoLocatorView source
class Local extends GeoLocatorBase {
const GEOLITE_CITY_DB = 'http://geolite.maxmind.com/download/geoip/database/GeoLite2-City.mmdb.gz';
const GEOLITE_COUNTRY_DB = 'http://geolite.maxmind.com/download/geoip/database/GeoLite2-Country.mmdb.gz';
protected $scheme = 'public';
/**
* {@inheritdoc}
*/
public function geolocate($ip_address) {
$reader = $this
->getReader();
// If the reader could not be initiated, then back out.
if (!$reader) {
return NULL;
}
try {
$record = $reader
->country($ip_address);
if ($this->geoIpConfig
->get('debug')) {
$this->logger
->notice($this
->t('Discovered %ip_address in the Maxmind local database', [
'%ip_address' => $ip_address,
]));
}
return $record->country->isoCode;
} catch (AddressNotFoundException $e) {
if ($this->geoIpConfig
->get('debug')) {
$this->logger
->notice($this
->t('Unable to look up %ip_address in the Maxmind local database', [
'%ip_address' => $ip_address,
]));
}
return NULL;
} catch (InvalidDatabaseException $e) {
$this->logger
->error($this
->t('The Maxmind database reader reported an invalid or corrupt database.'));
return NULL;
}
}
/**
* Get a dataset reader.
*
* @return \GeoIp2\Database\Reader|null
* Reader that can parse Mindmax datasets.
*/
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;
}
/**
* Get the current file scheme.
*
* @return string
* The file scheme.
*/
public function getScheme() {
return $this->scheme;
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
DependencySerializationTrait:: |
protected | property | An array of entity type IDs keyed by the property name of their storages. | |
DependencySerializationTrait:: |
protected | property | An array of service IDs keyed by property name used for serialization. | |
DependencySerializationTrait:: |
public | function | 1 | |
DependencySerializationTrait:: |
public | function | 2 | |
GeoLocatorBase:: |
protected | property | The GeoIP module configuration. | |
GeoLocatorBase:: |
protected | property | The logger. | |
GeoLocatorBase:: |
public static | function |
Creates an instance of the plugin. Overrides ContainerFactoryPluginInterface:: |
|
GeoLocatorBase:: |
public | function |
Get the plugin's description. Overrides GeoLocatorInterface:: |
|
GeoLocatorBase:: |
public | function |
Get the plugin's ID. Overrides GeoLocatorInterface:: |
|
GeoLocatorBase:: |
public | function |
Get the plugin's label. Overrides GeoLocatorInterface:: |
|
GeoLocatorBase:: |
public | function |
Constructs a PluginBase object. Overrides PluginBase:: |
|
Local:: |
protected | property | ||
Local:: |
constant | |||
Local:: |
constant | |||
Local:: |
public | function |
Performs geolocation on an address. Overrides GeoLocatorInterface:: |
|
Local:: |
protected | function | Get a dataset reader. | |
Local:: |
public | function | Get the current file scheme. | |
MessengerTrait:: |
protected | property | The messenger. | 29 |
MessengerTrait:: |
public | function | Gets the messenger. | 29 |
MessengerTrait:: |
public | function | Sets the messenger. | |
PluginBase:: |
protected | property | Configuration information passed into the plugin. | 1 |
PluginBase:: |
protected | property | The plugin implementation definition. | 1 |
PluginBase:: |
protected | property | The plugin_id. | |
PluginBase:: |
constant | A string which is used to separate base plugin IDs from the derivative ID. | ||
PluginBase:: |
public | function |
Gets the base_plugin_id of the plugin instance. Overrides DerivativeInspectionInterface:: |
|
PluginBase:: |
public | function |
Gets the derivative_id of the plugin instance. Overrides DerivativeInspectionInterface:: |
|
PluginBase:: |
public | function |
Gets the definition of the plugin implementation. Overrides PluginInspectionInterface:: |
3 |
PluginBase:: |
public | function |
Gets the plugin_id of the plugin instance. Overrides PluginInspectionInterface:: |
|
PluginBase:: |
public | function | Determines if the plugin is configurable. | |
StringTranslationTrait:: |
protected | property | The string translation service. | 1 |
StringTranslationTrait:: |
protected | function | Formats a string containing a count of items. | |
StringTranslationTrait:: |
protected | function | Returns the number of plurals supported by a given language. | |
StringTranslationTrait:: |
protected | function | Gets the string translation service. | |
StringTranslationTrait:: |
public | function | Sets the string translation service to use. | 2 |
StringTranslationTrait:: |
protected | function | Translates a string to the current language or to a given language. |