Provider.php in Geocoder 7.2
File
src/Plugin/Geocoder/Provider.php
View source
<?php
namespace Drupal\geocoder\Plugin\Geocoder;
use Drupal\Core\Logger\LoggerChannelInterface;
use Drupal\geocoder\Config;
use Drupal\geocoder\Plugin\GeocoderPlugin;
use Drupal\service_container\Messenger\MessengerInterface;
use Ivory\HttpAdapter\HttpAdapterInterface;
class Provider extends GeocoderPlugin implements ProviderInterface {
protected $messenger;
protected $loggerChannel;
private $adapter;
private $handler;
public function __construct($configuration, $plugin_id, $plugin_definition, HttpAdapterInterface $adapter, LoggerChannelInterface $logger_channel, MessengerInterface $messenger) {
$this->loggerChannel = $logger_channel;
$this->messenger = $messenger;
$this->adapter = $adapter;
parent::__construct($configuration, $plugin_id, $plugin_definition);
}
public function setHandler(\Geocoder\Provider\Provider $handler) {
$this->handler = $handler;
return $this;
}
public function getHandler() {
return $this->handler;
}
public function getAdapter() {
return $this->adapter;
}
public function geocode($data) {
$cid = $this
->getCacheCid($data);
if ($value = $this
->cache_get($cid)) {
return $value;
}
try {
$value = $this
->getHandler()
->geocode($data);
} catch (\Exception $e) {
throw $e;
} catch (\InvalidCredentials $e) {
throw $e;
}
$this
->cache_set($cid, $value);
return $value;
}
public function reverse($latitude, $longitude) {
$cid = $this
->getCacheCid($latitude, $longitude);
if ($value = $this
->cache_get($cid)) {
return $value;
}
try {
$value = $this
->getHandler()
->reverse($latitude, $longitude);
} catch (\Exception $e) {
throw $e;
}
$this
->cache_set($cid, $value);
return $value;
}
}