class SessionExistsCacheContext

Same name and namespace in other branches
  1. 11.x core/lib/Drupal/Core/Cache/Context/SessionExistsCacheContext.php \Drupal\Core\Cache\Context\SessionExistsCacheContext
  2. 10 core/lib/Drupal/Core/Cache/Context/SessionExistsCacheContext.php \Drupal\Core\Cache\Context\SessionExistsCacheContext
  3. 9 core/lib/Drupal/Core/Cache/Context/SessionExistsCacheContext.php \Drupal\Core\Cache\Context\SessionExistsCacheContext
  4. 8.9.x core/lib/Drupal/Core/Cache/Context/SessionExistsCacheContext.php \Drupal\Core\Cache\Context\SessionExistsCacheContext

Defines the SessionExistsCacheContext service, for "session or not" caching.

Cache context ID: 'session.exists'.

Hierarchy

Expanded class hierarchy of SessionExistsCacheContext

1 string reference to 'SessionExistsCacheContext'
core.services.yml in core/core.services.yml
core/core.services.yml
1 service uses SessionExistsCacheContext
cache_context.session.exists in core/core.services.yml
Drupal\Core\Cache\Context\SessionExistsCacheContext

File

core/lib/Drupal/Core/Cache/Context/SessionExistsCacheContext.php, line 14

Namespace

Drupal\Core\Cache\Context
View source
class SessionExistsCacheContext implements CacheContextInterface {
  
  /**
   * Constructs a new SessionExistsCacheContext class.
   *
   * @param \Drupal\Core\Session\SessionConfigurationInterface $sessionConfiguration
   *   The session configuration.
   * @param \Symfony\Component\HttpFoundation\RequestStack $requestStack
   *   The request stack.
   */
  public function __construct(protected SessionConfigurationInterface $sessionConfiguration, protected RequestStack $requestStack) {
  }
  
  /**
   * {@inheritdoc}
   */
  public static function getLabel() {
    return t('Session exists');
  }
  
  /**
   * {@inheritdoc}
   */
  public function getContext() {
    return $this->sessionConfiguration
      ->hasSession($this->requestStack
      ->getCurrentRequest()) ? '1' : '0';
  }
  
  /**
   * {@inheritdoc}
   */
  public function getCacheableMetadata() {
    return new CacheableMetadata();
  }

}

Members

Title Sort descending Modifiers Object type Summary Overriden Title
SessionExistsCacheContext::getCacheableMetadata public function Overrides CacheContextInterface::getCacheableMetadata
SessionExistsCacheContext::getContext public function Overrides CacheContextInterface::getContext
SessionExistsCacheContext::getLabel public static function Overrides CacheContextInterface::getLabel
SessionExistsCacheContext::__construct public function Constructs a new SessionExistsCacheContext class.

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.