You are here

class CacheContexts in Render cache 7.2

Same name in this branch
  1. 7.2 src/Cache/CacheContexts.php \Drupal\render_cache\Cache\CacheContexts
  2. 7.2 lib/Drupal/Core/Cache/CacheContexts.php \Drupal\Core\Cache\CacheContexts

Defines the CacheContexts service.

Provides CacheContexts service using the render_cache container.

Note: The original Drupal 8 CacheContexts service uses the Symfony ContainerInterface, which is not available here. So we over- write the constructor to enable us to use the functionality of the stock file.

Hierarchy

Expanded class hierarchy of CacheContexts

1 file declares its use of CacheContexts
CacheContextsTest.php in tests/src/Cache/CacheContextsTest.php
Contains \Drupal\render_cache\Tests\Cache\CacheContextsTest

File

src/Cache/CacheContexts.php, line 25
Contains \Drupal\render_cache\Cache\CacheContexts

Namespace

Drupal\render_cache\Cache
View source
class CacheContexts extends DrupalCacheContexts {

  /**
   * The service container.
   *
   * @var \Drupal\service_container\DependencyInjection\ContainerInterface
   */
  protected $container;

  /**
   * Constructs a CacheContexts object.
   *
   * @param \Drupal\service_container\DependencyInjection\ContainerInterface $container
   *   The current service container.
   * @param array $contexts
   *   An array of key-value pairs, where the keys are service names (which also
   *   serve as the corresponding cache context token) and the values are the
   *   cache context labels.
   */
  public function __construct(ContainerInterface $container, array $contexts) {
    $this->container = $container;
    $this->contexts = $contexts;
  }

}

Members

Namesort descending Modifiers Type Description Overrides
CacheContexts::$container protected property The service container. Overrides CacheContexts::$container
CacheContexts::$contexts protected property Available cache contexts and corresponding labels.
CacheContexts::convertTokensToKeys public function Converts cache context tokens to string representations of the context.
CacheContexts::getAll public function Provides an array of available cache contexts.
CacheContexts::getContext protected function Provides the string representation of a cache context.
CacheContexts::getLabels public function Provides an array of available cache context labels.
CacheContexts::getService protected function Retrieves a service from the container.
CacheContexts::__construct public function Constructs a CacheContexts object. Overrides CacheContexts::__construct