You are here

class AcquiaPlatformCdnPurger in Acquia Purge 8

Acquia Platform CDN (beta).

Plugin annotation


@PurgePurger(
  id = "acquia_platform_cdn",
  label = @Translation("Acquia Platform CDN (beta)"),
  configform = "",
  cooldown_time = 0.0,
  description = @Translation("Invalidate content from Acquia Platform CDN."),
  multi_instance = FALSE,
  types = {"url", "tag", "everything"},
)

Hierarchy

Expanded class hierarchy of AcquiaPlatformCdnPurger

File

src/Plugin/Purge/Purger/AcquiaPlatformCdnPurger.php, line 25

Namespace

Drupal\acquia_purge\Plugin\Purge\Purger
View source
class AcquiaPlatformCdnPurger extends PurgerBase implements DebuggerAwareInterface, PurgerInterface {
  use DebuggerAwareTrait;

  /**
   * The Acquia Platform CDN backend.
   *
   * @var null|\Drupal\acquia_purge\AcquiaPlatformCdn\BackendInterface
   */
  protected $backend = NULL;

  /**
   * Information object interfacing with the Acquia platform.
   *
   * @var \Drupal\acquia_purge\AcquiaCloud\PlatformInfoInterface
   */
  protected $platformInfo;

  /**
   * The Guzzle HTTP client.
   *
   * @var \GuzzleHttp\ClientInterface
   */
  protected $httpClient;

  /**
   * Constructs a AcquiaCdnPurger object.
   *
   * @param \Drupal\acquia_purge\AcquiaCloud\PlatformInfoInterface $acquia_purge_platforminfo
   *   Information object interfacing with the Acquia platform.
   * @param \GuzzleHttp\ClientInterface $http_client
   *   An HTTP client that can perform remote requests.
   * @param array $configuration
   *   A configuration array containing information about the plugin instance.
   * @param string $plugin_id
   *   The plugin_id for the plugin instance.
   * @param mixed $plugin_definition
   *   The plugin implementation definition.
   */
  public final function __construct(PlatformInfoInterface $acquia_purge_platforminfo, ClientInterface $http_client, array $configuration, $plugin_id, $plugin_definition) {
    parent::__construct($configuration, $plugin_id, $plugin_definition);
    $this->platformInfo = $acquia_purge_platforminfo;
    $this->httpClient = $http_client;
  }

  /**
   * {@inheritdoc}
   */
  public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) {
    return new static($container
      ->get('acquia_purge.platforminfo'), $container
      ->get('http_client'), $configuration, $plugin_id, $plugin_definition);
  }

  /**
   * {@inheritdoc}
   */
  public function hasRuntimeMeasurement() {
    return TRUE;
  }

  /**
   * Lazy load the underlying backend based on PlatformInfo CDN configuration.
   *
   * @warning
   *   Don't call this from the constructor!
   */
  protected function initializeBackend() {
    if (!is_null($this->backend)) {
      return;
    }
    $this
      ->debugger()
      ->callerAdd(__METHOD__);

    // Attempt to load the backend or halt code execution.
    $this->backend = BackendFactory::get($this->platformInfo, $this
      ->logger(), $this
      ->debugger(), $this->httpClient);
    if (!$this->backend) {
      throw new \RuntimeException("AcquiaPlatformCdnPurger has no backend!");
    }

    // Instantiate the backend and inject the logger.
    $this
      ->debugger()
      ->callerAdd($this->backend);
  }

  /**
   * {@inheritdoc}
   */
  public function invalidate(array $invalidations) {

    // Since we implemented ::routeTypeToMethod(), this Latin preciousness
    // shouldn't ever occur and when it does, will be easily recognized.
    throw new \Exception("Malum consilium quod mutari non potest!");
  }

  /**
   * Invalidate a set of tag invalidations.
   *
   * @see \Drupal\purge\Plugin\Purge\Purger\PurgerInterface::invalidate()
   * @see \Drupal\purge\Plugin\Purge\Purger\PurgerInterface::routeTypeToMethod()
   */
  public function invalidateTags(array $invalidations) {
    $this
      ->initializeBackend();
    $this
      ->debugger()
      ->callerAdd(__METHOD__);
    $this->backend
      ->invalidateTags($invalidations);
    $this
      ->debugger()
      ->callerRemove(__METHOD__);
  }

  /**
   * Invalidate a set of URL invalidations.
   *
   * @see \Drupal\purge\Plugin\Purge\Purger\PurgerInterface::invalidate()
   * @see \Drupal\purge\Plugin\Purge\Purger\PurgerInterface::routeTypeToMethod()
   */
  public function invalidateUrls(array $invalidations) {
    $this
      ->initializeBackend();
    $this
      ->debugger()
      ->callerAdd(__METHOD__);
    $this->backend
      ->invalidateUrls($invalidations);
    $this
      ->debugger()
      ->callerRemove(__METHOD__);
  }

  /**
   * Invalidate the entire CDN.
   *
   * @see \Drupal\purge\Plugin\Purge\Purger\PurgerInterface::invalidate()
   * @see \Drupal\purge\Plugin\Purge\Purger\PurgerInterface::routeTypeToMethod()
   */
  public function invalidateEverything(array $invalidations) {
    $this
      ->initializeBackend();
    $this
      ->debugger()
      ->callerAdd(__METHOD__);
    $this->backend
      ->invalidateEverything($invalidations);
    $this
      ->debugger()
      ->callerRemove(__METHOD__);
  }

  /**
   * {@inheritdoc}
   */
  public function routeTypeToMethod($type) {
    $methods = [
      'tag' => 'invalidateTags',
      'url' => 'invalidateUrls',
      'everything' => 'invalidateEverything',
    ];
    return isset($methods[$type]) ? $methods[$type] : 'invalidate';
  }

}

Members

Namesort descending Modifiers Type Description Overrides
AcquiaPlatformCdnPurger::$backend protected property The Acquia Platform CDN backend.
AcquiaPlatformCdnPurger::$httpClient protected property The Guzzle HTTP client.
AcquiaPlatformCdnPurger::$platformInfo protected property Information object interfacing with the Acquia platform.
AcquiaPlatformCdnPurger::create public static function Creates an instance of the plugin. Overrides PurgerBase::create
AcquiaPlatformCdnPurger::hasRuntimeMeasurement public function Indicates whether your purger utilizes dynamic runtime measurement. Overrides PurgerCapacityDataInterface::hasRuntimeMeasurement
AcquiaPlatformCdnPurger::initializeBackend protected function Lazy load the underlying backend based on PlatformInfo CDN configuration.
AcquiaPlatformCdnPurger::invalidate public function Invalidate content from external caches. Overrides PurgerInterface::invalidate
AcquiaPlatformCdnPurger::invalidateEverything public function Invalidate the entire CDN.
AcquiaPlatformCdnPurger::invalidateTags public function Invalidate a set of tag invalidations.
AcquiaPlatformCdnPurger::invalidateUrls public function Invalidate a set of URL invalidations.
AcquiaPlatformCdnPurger::routeTypeToMethod public function Route certain type of invalidations to other methods. Overrides PurgerBase::routeTypeToMethod
AcquiaPlatformCdnPurger::__construct final public function Constructs a AcquiaCdnPurger object. Overrides PurgerBase::__construct
DebuggerAwareTrait::$debuggerInstance private property The debugger instance.
DebuggerAwareTrait::debugger public function
DebuggerAwareTrait::setDebugger public function
DependencySerializationTrait::$_entityStorages protected property An array of entity type IDs keyed by the property name of their storages.
DependencySerializationTrait::$_serviceIds protected property An array of service IDs keyed by property name used for serialization.
DependencySerializationTrait::__sleep public function 1
DependencySerializationTrait::__wakeup public function 2
MessengerTrait::$messenger protected property The messenger. 29
MessengerTrait::messenger public function Gets the messenger. 29
MessengerTrait::setMessenger public function Sets the messenger.
PluginBase::$configuration protected property Configuration information passed into the plugin. 1
PluginBase::$pluginDefinition protected property The plugin implementation definition. 1
PluginBase::$pluginId protected property The plugin_id.
PluginBase::DERIVATIVE_SEPARATOR constant A string which is used to separate base plugin IDs from the derivative ID.
PluginBase::getBaseId public function Gets the base_plugin_id of the plugin instance. Overrides DerivativeInspectionInterface::getBaseId
PluginBase::getDerivativeId public function Gets the derivative_id of the plugin instance. Overrides DerivativeInspectionInterface::getDerivativeId
PluginBase::getPluginDefinition public function Gets the definition of the plugin implementation. Overrides PluginInspectionInterface::getPluginDefinition 3
PluginBase::getPluginId public function Gets the plugin_id of the plugin instance. Overrides PluginInspectionInterface::getPluginId
PluginBase::isConfigurable public function Determines if the plugin is configurable.
PurgeLoggerAwareTrait::$logger protected property Channel logger.
PurgeLoggerAwareTrait::logger public function
PurgerBase::$id protected property Unique instance ID for this purger.
PurgerBase::$runtimeMeasurement protected property The runtime measurement counter.
PurgerBase::delete public function The current instance of this purger plugin is about to be deleted. Overrides PurgerInterface::delete 1
PurgerBase::getCooldownTime public function Get the time in seconds to wait after invalidation. Overrides PurgerCapacityDataInterface::getCooldownTime
PurgerBase::getId public function Retrieve the unique instance ID for this purger instance. Overrides PurgerInterface::getId
PurgerBase::getIdealConditionsLimit public function Get the maximum number of invalidations that this purger can process. Overrides PurgerCapacityDataInterface::getIdealConditionsLimit 1
PurgerBase::getLabel public function Retrieve the user-readable label for this purger instance. Overrides PurgerInterface::getLabel
PurgerBase::getRuntimeMeasurement public function Get the runtime measurement counter. Overrides PurgerCapacityDataInterface::getRuntimeMeasurement
PurgerBase::getTimeHint public function Get the maximum number of seconds, processing a single invalidation takes. Overrides PurgerCapacityDataInterface::getTimeHint
PurgerBase::getTypes public function Retrieve the list of supported invalidation types. Overrides PurgerInterface::getTypes
PurgerBase::setRuntimeMeasurement public function Inject the runtime measurement counter. Overrides PurgerCapacityDataInterface::setRuntimeMeasurement
StringTranslationTrait::$stringTranslation protected property The string translation service. 1
StringTranslationTrait::formatPlural protected function Formats a string containing a count of items.
StringTranslationTrait::getNumberOfPlurals protected function Returns the number of plurals supported by a given language.
StringTranslationTrait::getStringTranslation protected function Gets the string translation service.
StringTranslationTrait::setStringTranslation public function Sets the string translation service to use. 2
StringTranslationTrait::t protected function Translates a string to the current language or to a given language.