You are here

class PurlCacheContext in Persistent URL 8

Hierarchy

Expanded class hierarchy of PurlCacheContext

1 string reference to 'PurlCacheContext'
purl.services.yml in ./purl.services.yml
purl.services.yml
1 service uses PurlCacheContext
cache_context.purl in ./purl.services.yml
Drupal\purl\Cache\Context\PurlCacheContext

File

src/Cache/Context/PurlCacheContext.php, line 12

Namespace

Drupal\purl\Cache\Context
View source
class PurlCacheContext implements CacheContextInterface, EventSubscriberInterface {
  protected $contexts = array();

  /**
   * Returns the label of the cache context.
   *
   * @return string
   *   The label of the cache context.
   */
  public static function getLabel() {
    return t('PURL Context');
  }

  /**
   * Returns the string representation of the cache context.
   *
   * A cache context service's name is used as a token (placeholder) cache key,
   * and is then replaced with the string returned by this method.
   *
   * @return string
   *   The string representation of the cache context.
   */
  public function getContext() {
    return json_encode($this->contexts);
  }

  /**
   * Gets the cacheability metadata for the context.
   *
   * There are three valid cases for the returned CacheableMetadata object:
   * - An empty object means this can be optimized away safely.
   * - A max-age of 0 means that this context can never be optimized away. It
   *   will never bubble up and cache tags will not be used.
   * - Any non-zero max-age and cache tags will bubble up into the cache item
   *   if this is optimized away to allow for invalidation if the context
   *   value changes.
   *
   *
   * @return \Drupal\Core\Cache\CacheableMetadata
   *   A cacheable metadata object.
   */
  public function getCacheableMetadata() {
    return new CacheableMetadata();
  }

  /**
   * Returns an array of event names this subscriber wants to listen to.
   *
   * The array keys are event names and the value can be:
   *
   *  * The method name to call (priority defaults to 0)
   *  * An array composed of the method name to call and the priority
   *  * An array of arrays composed of the method names to call and respective
   *    priorities, or 0 if unset
   *
   * For instance:
   *
   *  * array('eventName' => 'methodName')
   *  * array('eventName' => array('methodName', $priority))
   *  * array('eventName' => array(array('methodName1', $priority), array('methodName2')))
   *
   * @return array The event names to listen to
   */
  public static function getSubscribedEvents() {
    return [
      PurlEvents::MODIFIER_MATCHED => array(
        'onMatch',
      ),
    ];
  }
  public function onMatch(ModifierMatchedEvent $event) {
    $this->contexts[$event
      ->getMethod()] = $event
      ->getModifier();
    ksort($this->contexts);
  }

}

Members

Namesort descending Modifiers Type Description Overrides
PurlCacheContext::$contexts protected property
PurlCacheContext::getCacheableMetadata public function Gets the cacheability metadata for the context. Overrides CacheContextInterface::getCacheableMetadata
PurlCacheContext::getContext public function Returns the string representation of the cache context. Overrides CacheContextInterface::getContext
PurlCacheContext::getLabel public static function Returns the label of the cache context. Overrides CacheContextInterface::getLabel
PurlCacheContext::getSubscribedEvents public static function Returns an array of event names this subscriber wants to listen to.
PurlCacheContext::onMatch public function