PurgerBase.php in Purge 8.3
File
src/Plugin/Purge/Purger/PurgerBase.php
View source
<?php
namespace Drupal\purge\Plugin\Purge\Purger;
use Drupal\Core\Plugin\PluginBase;
use Drupal\purge\Logger\PurgeLoggerAwareTrait;
use Symfony\Component\DependencyInjection\ContainerInterface;
abstract class PurgerBase extends PluginBase implements PurgerInterface {
use PurgeLoggerAwareTrait;
protected $id;
protected $runtimeMeasurement = NULL;
public function __construct(array $configuration, $plugin_id, $plugin_definition) {
if (!is_string($configuration['id']) || empty($configuration['id'])) {
throw new \LogicException('Purger cannot be constructed without ID.');
}
$this->id = $configuration['id'];
unset($configuration['id']);
parent::__construct($configuration, $plugin_id, $plugin_definition);
}
public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) {
return new static($configuration, $plugin_id, $plugin_definition);
}
public function delete() {
if ($this->pluginDefinition['multi_instance']) {
throw new \LogicException('Plugin is multi-instantiable, ::delete() not implemented!');
}
}
public function getCooldownTime() {
return $this
->getPluginDefinition()['cooldown_time'];
}
public function getIdealConditionsLimit() {
return 100;
}
public function getId() {
return $this->id;
}
public function getLabel() {
$label = $this
->getPluginDefinition()['label'];
if ($this
->getPluginDefinition()['multi_instance']) {
return $this
->t('@label @id', [
'@label' => $label,
'@id' => $this->id,
]);
}
else {
return $label;
}
}
public function getRuntimeMeasurement() {
return $this->runtimeMeasurement;
}
public function getTimeHint() {
if (!$this
->hasRuntimeMeasurement()) {
throw new \LogicException('Since ::hasRuntimeMeasurement() returns FALSE, ::getTimeHint() needs to be implemented! Please read the PurgerCapacityDataInterface::hasRuntimeMeasurement() documentation.');
}
if (!is_null($this->runtimeMeasurement)) {
if (($measured_time = $this->runtimeMeasurement
->get()) > 0.0) {
return $measured_time;
}
}
return 4.0;
}
public function getTypes() {
return $this
->getPluginDefinition()['types'];
}
public function routeTypeToMethod($type) {
return 'invalidate';
}
public function setRuntimeMeasurement(RuntimeMeasurementInterface $measurement) {
$this->runtimeMeasurement = $measurement;
}
}
Classes
Name |
Description |
PurgerBase |
Provides a base class for all purgers - the cache invalidation executors. |