You are here

class TagsHeaderValue in Acquia Purge 8

Provides simple value object for cache tag headers.

Hierarchy

Expanded class hierarchy of TagsHeaderValue

2 files declare their use of TagsHeaderValue
AcquiaCloudPurger.php in src/Plugin/Purge/Purger/AcquiaCloudPurger.php
FastlyBackend.php in src/AcquiaPlatformCdn/FastlyBackend.php

File

src/Plugin/Purge/TagsHeader/TagsHeaderValue.php, line 8

Namespace

Drupal\acquia_purge\Plugin\Purge\TagsHeader
View source
class TagsHeaderValue {

  /**
   * String: separation character used.
   */
  const SEPARATOR = ' ';

  /**
   * List of original cache tags.
   *
   * @var string[]
   */
  protected $tags = [];

  /**
   * List of hashed cache tags.
   *
   * @var string[]
   */
  protected $tagsHashed = [];

  /**
   * Constructs a TagsHeaderValue object.
   *
   * @param string[] $tags
   *   Non-associative array cache tags.
   * @param string[] $tags_hashed
   *   Non-associative array with hashed cache tags.
   *
   * @throws \LogicException
   *   Thrown when both tags arrays aren't of equal length.
   */
  public function __construct(array $tags, array $tags_hashed) {
    if (count($tags) !== count($tags_hashed)) {
      throw new \LogicException("TagsHeaderValue received unequal tag sets!");
    }
    $this->tags = $tags;
    $this->tagsHashed = $tags_hashed;
  }

  /**
   * Generate the header value for a cache tags header.
   *
   * @return string
   *   String representation of the cache tags for use on headers.
   */
  public function __toString() {
    return implode(self::SEPARATOR, $this->tagsHashed);
  }

  /**
   * Get an associative array mapping keys.
   *
   * @return array
   *   Associative mapping original and hashed cache tags.
   */
  public function getTagsMap() {
    return array_combine($this->tags, $this->tagsHashed);
  }

}

Members

Namesort descending Modifiers Type Description Overrides
TagsHeaderValue::$tags protected property List of original cache tags.
TagsHeaderValue::$tagsHashed protected property List of hashed cache tags.
TagsHeaderValue::getTagsMap public function Get an associative array mapping keys.
TagsHeaderValue::SEPARATOR constant String: separation character used.
TagsHeaderValue::__construct public function Constructs a TagsHeaderValue object.
TagsHeaderValue::__toString public function Generate the header value for a cache tags header.