public function BrowscapEndpoint::getVersion in Browscap 8.3
Gets version of latest Browscap data.
Return value
int|string Either an error code (BROWSCAP_IMPORT_VERSION_ERROR) or the latest Browscap data version.
1 method overrides BrowscapEndpoint::getVersion()
- MockBrowscapEndpoint::getVersion in src/
Tests/ MockBrowscapEndpoint.php - Gets version of latest Browscap data.
File
- src/
BrowscapEndpoint.php, line 22
Class
- BrowscapEndpoint
- Browscap endpoint.
Namespace
Drupal\browscapCode
public function getVersion() {
$config = \Drupal::config('browscap.settings');
// Retrieve the current browscap data version number using HTTP.
$client = \Drupal::httpClient();
try {
$browscapVersionURL = $config
->get('version_url');
$response = $client
->get($browscapVersionURL);
// Expected result.
$current_version = (string) $response
->getBody();
} catch (RequestException $e) {
\Drupal::logger('browscap')
->error($e
->getMessage());
}
// Log an error if the browscap version number could not be retrieved.
if (isset($current_version->error)) {
// Log a message with the watchdog.
\Drupal::logger('browscap')
->error("Couldn't check version: %error", [
'%error' => $current_version->error,
]);
return BrowscapImporter::BROWSCAP_IMPORT_VERSION_ERROR;
}
// Sanitize the returned version number.
$current_version = Html::escape(trim($current_version));
return $current_version;
}