InvalidationsService.php in Purge 8.3
File
src/Plugin/Purge/Invalidation/InvalidationsService.php
View source
<?php
namespace Drupal\purge\Plugin\Purge\Invalidation;
use Drupal\Component\Plugin\PluginManagerInterface;
use Drupal\purge\Plugin\Purge\Invalidation\Exception\TypeUnsupportedException;
use Drupal\purge\Plugin\Purge\Purger\PurgersServiceInterface;
use Drupal\purge\Plugin\Purge\Queue\ProxyItemInterface;
use Drupal\purge\ServiceBase;
class InvalidationsService extends ServiceBase implements InvalidationsServiceInterface {
protected $instanceCounter = 0;
protected $instanceCounterImmutables = -1;
protected $purgePurgers;
public function __construct(PluginManagerInterface $pluginManager, PurgersServiceInterface $purge_purgers) {
$this->pluginManager = $pluginManager;
$this->purgePurgers = $purge_purgers;
}
protected function createInstance($plugin_id, $expression, $id) {
return $this->pluginManager
->createInstance($plugin_id, [
'expression' => $expression,
'id' => $id,
]);
}
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);
}
public function getImmutable($plugin_id, $expression = NULL) {
$id = $this->instanceCounterImmutables--;
return new ImmutableInvalidation($this
->createInstance($plugin_id, $expression, $id));
}
public function getFromQueueData($item_data) {
$instance = $this
->createInstance($item_data[ProxyItemInterface::DATA_INDEX_TYPE], $item_data[ProxyItemInterface::DATA_INDEX_EXPRESSION], $this->instanceCounter++);
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);
}
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;
}
public function getImmutableFromQueueData($item_data) {
$instance = $this
->createInstance($item_data[ProxyItemInterface::DATA_INDEX_TYPE], $item_data[ProxyItemInterface::DATA_INDEX_EXPRESSION], $this->instanceCounterImmutables--);
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);
}
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);
}
}