class SessionExistsCacheContext in Drupal 10
Same name and namespace in other branches
- 8 core/lib/Drupal/Core/Cache/Context/SessionExistsCacheContext.php \Drupal\Core\Cache\Context\SessionExistsCacheContext
- 9 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
- class \Drupal\Core\Cache\Context\SessionExistsCacheContext implements CacheContextInterface
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
File
- core/
lib/ Drupal/ Core/ Cache/ Context/ SessionExistsCacheContext.php, line 14
Namespace
Drupal\Core\Cache\ContextView source
class SessionExistsCacheContext implements CacheContextInterface {
/**
* The session configuration.
*
* @var \Drupal\Core\Session\SessionConfigurationInterface
*/
protected $sessionConfiguration;
/**
* The request stack.
*
* @var \Symfony\Component\HttpFoundation\RequestStack
*/
protected $requestStack;
/**
* Constructs a new SessionExistsCacheContext class.
*
* @param \Drupal\Core\Session\SessionConfigurationInterface $session_configuration
* The session configuration.
* @param \Symfony\Component\HttpFoundation\RequestStack $request_stack
* The request stack.
*/
public function __construct(SessionConfigurationInterface $session_configuration, RequestStack $request_stack) {
$this->sessionConfiguration = $session_configuration;
$this->requestStack = $request_stack;
}
/**
* {@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
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
SessionExistsCacheContext:: |
protected | property | The request stack. | |
SessionExistsCacheContext:: |
protected | property | The session configuration. | |
SessionExistsCacheContext:: |
public | function |
Gets the cacheability metadata for the context. Overrides CacheContextInterface:: |
|
SessionExistsCacheContext:: |
public | function |
Returns the string representation of the cache context. Overrides CacheContextInterface:: |
|
SessionExistsCacheContext:: |
public static | function |
Returns the label of the cache context. Overrides CacheContextInterface:: |
|
SessionExistsCacheContext:: |
public | function | Constructs a new SessionExistsCacheContext class. |