You are here

class ProxyItem in Purge 8.3

Provides a proxy item.

Queue proxy objects act as middle man between our high level invalidation objects and the lower level \Drupal\Core\Queue\QueueInterface API. As Purge queue plugins extend core's API, these are also unaware of invalidation objects and therefore proxy objects play a key translation role. A proxy has the properties 'data', 'item_id' and 'created', of which the data is stored in the given \Drupal\purge\Plugin\Purge\Queue\TxBufferInterface derivative.

Hierarchy

Expanded class hierarchy of ProxyItem

1 file declares its use of ProxyItem
ProxyItemTest.php in tests/src/Kernel/Queue/ProxyItemTest.php

File

src/Plugin/Purge/Queue/ProxyItem.php, line 18

Namespace

Drupal\purge\Plugin\Purge\Queue
View source
class ProxyItem implements ProxyItemInterface {

  /**
   * The proxied invalidation object.
   *
   * @var \Drupal\purge\Plugin\Purge\Invalidation\InvalidationInterface
   */
  protected $invalidation;

  /**
   * The 'purge.queue.txbuffer' service.
   *
   * @var \Drupal\purge\Plugin\Purge\Queue\TxBufferInterface
   */
  protected $buffer;

  /**
   * Describes the accessible properties and if they're RO (FALSE) or RW (TRUE).
   *
   * @var bool[string]
   */
  protected $properties = [
    'item_id' => TRUE,
    'created' => TRUE,
    'data' => FALSE,
  ];

  /**
   * The unique ID from \Drupal\Core\Queue\QueueInterface::createItem().
   *
   * @var mixed|null
   *
   * @see \Drupal\Core\Queue\QueueInterface::createItem
   * @see \Drupal\Core\Queue\QueueInterface::claimItem
   */
  private $item_id;

  // phpcs:ignore -- property matching Drupal core naming!

  /**
   * Purge specific data to be associated with the new task in the queue.
   *
   * @var mixed
   *
   * @see \Drupal\Core\Queue\QueueInterface::createItem
   * @see \Drupal\Core\Queue\QueueInterface::claimItem
   */
  private $data;

  /**
   * Timestamp when the item was put into the queue.
   *
   * @var mixed|null
   *
   * @see \Drupal\Core\Queue\QueueInterface::createItem
   * @see \Drupal\Core\Queue\QueueInterface::claimItem
   */
  private $created;

  /**
   * {@inheritdoc}
   */
  public function __construct(InvalidationInterface $invalidation, TxBufferInterface $buffer) {
    $this->invalidation = $invalidation;
    $this->buffer = $buffer;
  }

  /**
   * {@inheritdoc}
   */
  public function __get($name) {
    if (!isset($this->properties[$name])) {
      throw new InvalidPropertyException("The property '{$name}' does not exist.");
    }

    // The 'data' property describes the purge queue item in such a way that
    // \Drupal\purge\Plugin\Purge\Invalidation\InvalidationsServiceInterface is
    // able to recreate it easily.
    if ($name === 'data') {
      return [
        self::DATA_INDEX_TYPE => $this->invalidation
          ->getType(),
        self::DATA_INDEX_STATES => $this->invalidation
          ->getStates(),
        self::DATA_INDEX_EXPRESSION => $this->invalidation
          ->getExpression(),
        self::DATA_INDEX_PROPERTIES => $this->invalidation
          ->getProperties(),
      ];
    }
    else {
      return $this->buffer
        ->getProperty($this->invalidation, $name, NULL);
    }
  }

  /**
   * {@inheritdoc}
   */
  public function __set($name, $value) {
    if (!isset($this->properties[$name])) {
      throw new InvalidPropertyException("The property '{$name}' does not exist.");
    }
    if (!$this->properties[$name]) {
      throw new InvalidPropertyException("The property '{$name}' is read-only.");
    }
    $this->buffer
      ->setProperty($this->invalidation, $name, $value);
  }

}

Members

Namesort descending Modifiers Type Description Overrides
ProxyItem::$buffer protected property The 'purge.queue.txbuffer' service.
ProxyItem::$created private property Timestamp when the item was put into the queue.
ProxyItem::$data private property Purge specific data to be associated with the new task in the queue.
ProxyItem::$invalidation protected property The proxied invalidation object.
ProxyItem::$item_id private property The unique ID from \Drupal\Core\Queue\QueueInterface::createItem().
ProxyItem::$properties protected property Describes the accessible properties and if they're RO (FALSE) or RW (TRUE).
ProxyItem::__construct public function Construct a proxy item object. Overrides ProxyItemInterface::__construct
ProxyItem::__get public function Retrieve a property. Overrides ProxyItemInterface::__get
ProxyItem::__set public function Set a writable property. Overrides ProxyItemInterface::__set
ProxyItemInterface::DATA_INDEX_EXPRESSION constant The array index in the data property that holds the expression.
ProxyItemInterface::DATA_INDEX_PROPERTIES constant The array index in the data property that holds the purger properties.
ProxyItemInterface::DATA_INDEX_STATES constant The array index in the data property that holds the states.
ProxyItemInterface::DATA_INDEX_TYPE constant The array index in the data property where the invalidation type is stored.