class InvalidationsService in Purge 8.3
Provides a service that instantiates invalidation objects on-demand.
Hierarchy
- class \Drupal\Core\DependencyInjection\ServiceProviderBase implements ServiceModifierInterface, ServiceProviderInterface
- class \Drupal\purge\ServiceBase implements ServiceInterface
- class \Drupal\purge\Plugin\Purge\Invalidation\InvalidationsService implements InvalidationsServiceInterface
- class \Drupal\purge\ServiceBase implements ServiceInterface
Expanded class hierarchy of InvalidationsService
1 string reference to 'InvalidationsService'
1 service uses InvalidationsService
File
- src/
Plugin/ Purge/ Invalidation/ InvalidationsService.php, line 14
Namespace
Drupal\purge\Plugin\Purge\InvalidationView source
class InvalidationsService extends ServiceBase implements InvalidationsServiceInterface {
/**
* Instance counter.
*
* Incremental ID counter for handing out unique instance IDs.
*
* @var int
*/
protected $instanceCounter = 0;
/**
* Immutable instance counter.
*
* As immutable instances cannot change the queue, they are counted negative
* and the counter only decrements. Its IDs can never clash with real ones.
*
* @var int
*/
protected $instanceCounterImmutables = -1;
/**
* The 'purge.purgers' service.
*
* @var \Drupal\purge\Plugin\Purge\Purger\PurgersServiceInterface
*/
protected $purgePurgers;
/**
* Construct the invalidation service.
*
* @param \Drupal\Component\Plugin\PluginManagerInterface $pluginManager
* The plugin manager for this service.
* @param \Drupal\purge\Plugin\Purge\Purger\PurgersServiceInterface $purge_purgers
* The purgers service.
*/
public function __construct(PluginManagerInterface $pluginManager, PurgersServiceInterface $purge_purgers) {
$this->pluginManager = $pluginManager;
$this->purgePurgers = $purge_purgers;
}
/**
* Retrieve a new instance from the plugin manager.
*
* @param string $plugin_id
* The id of the invalidation type being instantiated.
* @param mixed|null $expression
* Value - usually string - that describes the kind of invalidation, NULL
* when the type of invalidation doesn't require $expression. Types usually
* validate the given expression and throw exceptions for bad input.
* @param int $id
* The numeric identifier of this instance.
*
* @return \Drupal\purge\Plugin\Purge\Invalidation\InvalidationInterface
* The invalidation object.
*/
protected function createInstance($plugin_id, $expression, $id) {
return $this->pluginManager
->createInstance($plugin_id, [
'expression' => $expression,
'id' => $id,
]);
}
/**
* {@inheritdoc}
*/
public function get($plugin_id, $expression = NULL) {
if (!in_array($plugin_id, $this->purgePurgers
->getTypes())) {
throw new TypeUnsupportedException($plugin_id);
}
$id = $this->instanceCounter++;
return $this
->createInstance($plugin_id, $expression, $id);
}
/**
* {@inheritdoc}
*/
public function getImmutable($plugin_id, $expression = NULL) {
$id = $this->instanceCounterImmutables--;
return new ImmutableInvalidation($this
->createInstance($plugin_id, $expression, $id));
}
/**
* {@inheritdoc}
*/
public function getFromQueueData($item_data) {
$instance = $this
->createInstance($item_data[ProxyItemInterface::DATA_INDEX_TYPE], $item_data[ProxyItemInterface::DATA_INDEX_EXPRESSION], $this->instanceCounter++);
// Replay stored purger states.
if (isset($item_data[ProxyItemInterface::DATA_INDEX_STATES])) {
foreach ($item_data[ProxyItemInterface::DATA_INDEX_STATES] as $id => $state) {
$instance
->setStateContext($id);
$instance
->setState($state);
}
$instance
->setStateContext(NULL);
}
// Replay stored properties.
if (isset($item_data[ProxyItemInterface::DATA_INDEX_PROPERTIES])) {
foreach ($item_data[ProxyItemInterface::DATA_INDEX_PROPERTIES] as $id => $properties) {
$instance
->setStateContext($id);
foreach ($properties as $key => $value) {
$instance
->setProperty($key, $value);
}
}
$instance
->setStateContext(NULL);
}
return $instance;
}
/**
* {@inheritdoc}
*/
public function getImmutableFromQueueData($item_data) {
$instance = $this
->createInstance($item_data[ProxyItemInterface::DATA_INDEX_TYPE], $item_data[ProxyItemInterface::DATA_INDEX_EXPRESSION], $this->instanceCounterImmutables--);
// Replay stored purger states.
if (isset($item_data[ProxyItemInterface::DATA_INDEX_STATES])) {
foreach ($item_data[ProxyItemInterface::DATA_INDEX_STATES] as $id => $state) {
$instance
->setStateContext($id);
$instance
->setState($state);
}
$instance
->setStateContext(NULL);
}
// Replay stored properties.
if (isset($item_data[ProxyItemInterface::DATA_INDEX_PROPERTIES])) {
foreach ($item_data[ProxyItemInterface::DATA_INDEX_PROPERTIES] as $id => $properties) {
$instance
->setStateContext($id);
foreach ($properties as $key => $value) {
$instance
->setProperty($key, $value);
}
}
$instance
->setStateContext(NULL);
}
return new ImmutableInvalidation($instance);
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
InvalidationsService:: |
protected | property | Instance counter. | |
InvalidationsService:: |
protected | property | Immutable instance counter. | |
InvalidationsService:: |
protected | property | The 'purge.purgers' service. | |
InvalidationsService:: |
protected | function | Retrieve a new instance from the plugin manager. | |
InvalidationsService:: |
public | function |
Create a new invalidation object of the given type. Overrides InvalidationsServiceInterface:: |
|
InvalidationsService:: |
public | function |
Replicate a invalidation object from serialized queue item data. Overrides InvalidationsServiceInterface:: |
|
InvalidationsService:: |
public | function |
Create a new immutable invalidation object of the given type. Overrides InvalidationsServiceInterface:: |
|
InvalidationsService:: |
public | function |
Replicate a immutable invalidation object from serialized queue item data. Overrides InvalidationsServiceInterface:: |
|
InvalidationsService:: |
public | function | Construct the invalidation service. | |
ServiceBase:: |
protected | property | The plugin manager for the given service. | |
ServiceBase:: |
protected | property | The list of all available plugins and their definitions. | |
ServiceBase:: |
protected | property | The list of all enabled plugins and their definitions. | |
ServiceBase:: |
public | function |
Retrieve a list of all available plugins providing the service. Overrides ServiceInterface:: |
1 |
ServiceBase:: |
public | function |
Retrieve the configured plugin_ids that the service will use. Overrides ServiceInterface:: |
6 |
ServiceBase:: |
public | function |
Find out whether the given plugin_id is enabled. Overrides ServiceInterface:: |
|
ServiceBase:: |
public | function |
Reload the service and reinstantiate all enabled plugins. Overrides ServiceInterface:: |
6 |
ServiceProviderBase:: |
public | function |
Modifies existing service definitions. Overrides ServiceModifierInterface:: |
5 |
ServiceProviderBase:: |
public | function |
Registers services to the container. Overrides ServiceProviderInterface:: |
1 |