You are here

class MasqueradeCacheContext in Masquerade 8.2

Defines the MasqueradeCacheContext service, for "masquerade" caching.

Cache context ID: 'session.is_masquerading'.

Hierarchy

Expanded class hierarchy of MasqueradeCacheContext

1 string reference to 'MasqueradeCacheContext'
masquerade.services.yml in ./masquerade.services.yml
masquerade.services.yml
1 service uses MasqueradeCacheContext
cache_context.session.is_masquerading in ./masquerade.services.yml
Drupal\masquerade\Cache\MasqueradeCacheContext

File

src/Cache/MasqueradeCacheContext.php, line 15

Namespace

Drupal\masquerade\Cache
View source
class MasqueradeCacheContext extends RequestStackCacheContextBase implements CacheContextInterface {

  /**
   * {@inheritdoc}
   */
  public static function getLabel() {
    return new TranslatableMarkup('User is masquerading');
  }

  /**
   * {@inheritdoc}
   */
  public function getContext() {
    if ($request = $this->requestStack
      ->getCurrentRequest()) {
      if ($request
        ->hasSession() && ($session = $request
        ->getSession())) {
        if ($session
          ->has('masquerading')) {

          // Previous account supposed to be Authenticated.
          return '1';
        }
      }
    }
    return '0';
  }

  /**
   * {@inheritdoc}
   */
  public function getCacheableMetadata() {
    return new CacheableMetadata();
  }

}

Members

Namesort descending Modifiers Type Description Overrides
MasqueradeCacheContext::getCacheableMetadata public function Gets the cacheability metadata for the context. Overrides CacheContextInterface::getCacheableMetadata
MasqueradeCacheContext::getContext public function Returns the string representation of the cache context. Overrides CacheContextInterface::getContext
MasqueradeCacheContext::getLabel public static function Returns the label of the cache context. Overrides CacheContextInterface::getLabel
RequestStackCacheContextBase::$requestStack protected property The request stack.
RequestStackCacheContextBase::__construct public function Constructs a new RequestStackCacheContextBase class.