private function SmartIpEventSubscriber::checkBinFile in Smart IP 8.3
Same name and namespace in other branches
- 8.4 modules/smart_ip_ip2location_bin_db/src/EventSubscriber/SmartIpEventSubscriber.php \Drupal\smart_ip_ip2location_bin_db\EventSubscriber\SmartIpEventSubscriber::checkBinFile()
Check IP2Location binary database file if valid.
Parameters
string $file: IP2Location binary database file absolute path.
int $ipVersion: The IP address version: 4 or 6.
Return value
array
2 calls to SmartIpEventSubscriber::checkBinFile()
- SmartIpEventSubscriber::processQuery in modules/
smart_ip_ip2location_bin_db/ src/ EventSubscriber/ SmartIpEventSubscriber.php - Act on \Drupal\smart_ip\SmartIp::query() when executed and if selected as Smart IP data source, query the IP address against its database.
- SmartIpEventSubscriber::validateFormSettings in modules/
smart_ip_ip2location_bin_db/ src/ EventSubscriber/ SmartIpEventSubscriber.php - Act on validation of main Smart IP admin settings form.
File
- modules/
smart_ip_ip2location_bin_db/ src/ EventSubscriber/ SmartIpEventSubscriber.php, line 535 - Contains \Drupal\smart_ip_ip2location_bin_db\EventSubscriber\SmartIpEventSubscriber.
Class
- SmartIpEventSubscriber
- Core functionality of this Smart IP data source module. Listens to Smart IP override events.
Namespace
Drupal\smart_ip_ip2location_bin_db\EventSubscriberCode
private function checkBinFile($file, $ipVersion = Ip2locationBinDb::IPV4_VERSION) {
$error['msg'] = '';
$error['code'] = Ip2locationBinDb::DB_NO_ERROR;
if (!file_exists($file)) {
$error['code'] = Ip2locationBinDb::DB_NOT_EXIST_ERROR;
}
else {
try {
// Check IP2Location binary database file if valid
if ($ipVersion == Ip2locationBinDb::IPV4_VERSION) {
$ip = '8.8.8.8';
}
else {
$ip = '2001:4860:4860::8888';
}
$reader = new \IP2Location\Database($file, \IP2Location\Database::FILE_IO);
$record = $reader
->lookup($ip, \IP2Location\Database::COUNTRY);
if (strtotime($reader
->getDate()) <= 0 || empty($record['countryCode'])) {
$error['code'] = Ip2locationBinDb::DB_READ_ERROR;
}
} catch (\Exception $e) {
$error['msg'] = $e
->getMessage();
$error['code'] = Ip2locationBinDb::DB_LOAD_ERROR;
}
}
return $error;
}