You are here

class PendingPersistentLogin in Persistent Login 8

A policy preventing caching of pages with pending persistent login cookies.

Hierarchy

Expanded class hierarchy of PendingPersistentLogin

1 string reference to 'PendingPersistentLogin'
persistent_login.services.yml in ./persistent_login.services.yml
persistent_login.services.yml
1 service uses PendingPersistentLogin
persistent_login.page_cache_request_policy.pending_persistent_login in ./persistent_login.services.yml
Drupal\persistent_login\PageCache\RequestPolicy\PendingPersistentLogin

File

src/PageCache/RequestPolicy/PendingPersistentLogin.php, line 13

Namespace

Drupal\persistent_login\PageCache\RequestPolicy
View source
class PendingPersistentLogin implements RequestPolicyInterface {

  /**
   * The session configuration.
   *
   * @var \Drupal\Core\Session\SessionConfigurationInterface
   */
  protected $sessionConfiguration;

  /**
   * The cookie helper service.
   *
   * @var \Drupal\persistent_login\CookieHelperInterface
   */
  protected $cookieHelper;

  /**
   * Instantiates a new PendingPersistentLogin object.
   *
   * @param \Drupal\persistent_login\CookieHelperInterface $cookie_helper
   *   The cookie helper service.
   * @param \Drupal\Core\Session\SessionConfigurationInterface $session_configuration
   *   The session configuration.
   */
  public function __construct(CookieHelperInterface $cookie_helper, SessionConfigurationInterface $session_configuration) {
    $this->cookieHelper = $cookie_helper;
    $this->sessionConfiguration = $session_configuration;
  }

  /**
   * {@inheritdoc}
   */
  public function check(Request $request) {

    // Prevent the serving of cached pages for anonymous users if a persistent
    // login cookie is present.
    if (!$this->sessionConfiguration
      ->hasSession($request) && $this->cookieHelper
      ->hasCookie($request)) {
      return static::DENY;
    }
    return NULL;
  }

}

Members

Namesort descending Modifiers Type Description Overrides
PendingPersistentLogin::$cookieHelper protected property The cookie helper service.
PendingPersistentLogin::$sessionConfiguration protected property The session configuration.
PendingPersistentLogin::check public function Determines whether delivery of a cached page should be attempted. Overrides RequestPolicyInterface::check
PendingPersistentLogin::__construct public function Instantiates a new PendingPersistentLogin object.
RequestPolicyInterface::ALLOW constant Allow delivery of cached pages.
RequestPolicyInterface::DENY constant Deny delivery of cached pages.