View source
<?php
declare (strict_types=1);
namespace Drupal\geocoder;
use Drupal\Component\Plugin\ConfigurableInterface;
use Drupal\Core\Cache\CacheBackendInterface;
use Drupal\Core\Config\ConfigFactoryInterface;
use Drupal\Core\Config\TypedConfigManagerInterface;
use Drupal\Core\Language\LanguageManagerInterface;
use Drupal\Core\Plugin\PluginFormInterface;
use Drupal\geocoder\Traits\ConfigurableProviderTrait;
use Http\Client\HttpClient;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Drupal\Component\Plugin\Exception\InvalidPluginDefinitionException;
abstract class ConfigurableProviderUsingHandlerWithAdapterBase extends ProviderUsingHandlerWithAdapterBase implements ConfigurableInterface, PluginFormInterface {
use ConfigurableProviderTrait;
protected $typedConfigManager;
protected $throttle;
public function __construct(array $configuration, $plugin_id, $plugin_definition, ConfigFactoryInterface $config_factory, CacheBackendInterface $cache_backend, LanguageManagerInterface $language_manager, TypedConfigManagerInterface $typed_config_manager, HttpClient $http_adapter, GeocoderThrottleInterface $throttle) {
try {
$this->typedConfigManager = $typed_config_manager;
parent::__construct($configuration, $plugin_id, $plugin_definition, $config_factory, $cache_backend, $language_manager, $http_adapter);
$this
->setConfiguration($configuration);
$this->throttle = $throttle;
} catch (InvalidPluginDefinitionException $e) {
watchdog_exception('geocoder', $e);
}
}
public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) {
return new static($configuration, $plugin_id, $plugin_definition, $container
->get('config.factory'), $container
->get('cache.geocoder'), $container
->get('language_manager'), $container
->get('config.typed'), $container
->get('geocoder.http_adapter'), $container
->get('geocoder.throttle'));
}
protected function doGeocode($source) {
$this->throttle
->waitForAvailability($this->pluginId, isset($this->configuration['throttle']) ? $this->configuration['throttle'] : []);
return parent::doGeocode($source);
}
protected function doReverse($latitude, $longitude) {
$this->throttle
->waitForAvailability($this->pluginId, isset($this->configuration['throttle']) ? $this->configuration['throttle'] : []);
return parent::doReverse($latitude, $longitude);
}
}