You are here

final class CartTokenSessionConfiguration in Commerce Cart API 8

Decorates SessionConfiguration to support cart tokens.

If a cart token header or query parameter is present, return that a session is active. This prevents page_cache from caching the response. This might may be removed once page_cache supports Vary headers.

@link https://www.drupal.org/project/drupal/issues/2972483

Hierarchy

Expanded class hierarchy of CartTokenSessionConfiguration

1 file declares its use of CartTokenSessionConfiguration
CommerceCartApiServiceProvider.php in src/CommerceCartApiServiceProvider.php

File

src/Session/CartTokenSessionConfiguration.php, line 18

Namespace

Drupal\commerce_cart_api\Session
View source
final class CartTokenSessionConfiguration implements SessionConfigurationInterface {

  /**
   * The decorated service.
   *
   * @var \Drupal\Core\Session\SessionConfigurationInterface
   */
  private $decorated;

  /**
   * {@inheritdoc}
   */
  public function __construct(SessionConfigurationInterface $decorated) {
    $this->decorated = $decorated;
  }

  /**
   * {@inheritdoc}
   */
  public function hasSession(Request $request) {
    return $this->decorated
      ->hasSession($request) || $request->headers
      ->has(CartTokenSession::HEADER_NAME) || $request->query
      ->has(CartTokenSession::QUERY_NAME);
  }

  /**
   * {@inheritdoc}
   */
  public function getOptions(Request $request) {
    return $this->decorated
      ->getOptions($request);
  }

}

Members

Namesort descending Modifiers Type Description Overrides
CartTokenSessionConfiguration::$decorated private property The decorated service.
CartTokenSessionConfiguration::getOptions public function Returns a list of options suitable for passing to the session storage. Overrides SessionConfigurationInterface::getOptions
CartTokenSessionConfiguration::hasSession public function Determines whether a session identifier is on the request. Overrides SessionConfigurationInterface::hasSession
CartTokenSessionConfiguration::__construct public function