You are here

class Session in Zircon Profile 8

Same name in this branch
  1. 8 vendor/behat/mink/src/Session.php \Behat\Mink\Session
  2. 8 vendor/symfony/http-foundation/Session/Session.php \Symfony\Component\HttpFoundation\Session\Session
  3. 8 core/lib/Drupal/Core/StackMiddleware/Session.php \Drupal\Core\StackMiddleware\Session
Same name and namespace in other branches
  1. 8.0 core/lib/Drupal/Core/StackMiddleware/Session.php \Drupal\Core\StackMiddleware\Session

Wrap session logic around a HTTP request.

Note, the session service is not injected into this class in order to prevent premature initialization of session storage (database). Instead the session service is retrieved from the container only when handling the request.

Hierarchy

Expanded class hierarchy of Session

9 string references to 'Session'
core.services.yml in core/core.services.yml
core/core.services.yml
language.schema.yml in core/modules/language/config/schema/language.schema.yml
core/modules/language/config/schema/language.schema.yml
MemcacheSessionTestCase::sessionReset in modules/memcache/tests/memcache-session.test
Reset the cookie file so that it refers to the specified user.
MemcacheSessionTestCase::testDataPersistence in modules/memcache/tests/memcache-session.test
Test data persistence via the session_test module callbacks. Also tests drupal_session_count() since session data is already generated here.
MemcacheSessionTestCase::testSessionSaveRegenerate in modules/memcache/tests/memcache-session.test
Tests for drupal_save_session() and drupal_session_regenerate().

... See full list

1 service uses Session
http_middleware.session in core/core.services.yml
Drupal\Core\StackMiddleware\Session

File

core/lib/Drupal/Core/StackMiddleware/Session.php, line 21
Contains \Drupal\Core\StackMiddleware\Session.

Namespace

Drupal\Core\StackMiddleware
View source
class Session implements HttpKernelInterface {
  use ContainerAwareTrait;

  /**
   * The wrapped HTTP kernel.
   *
   * @var \Symfony\Component\HttpKernel\HttpKernelInterface
   */
  protected $httpKernel;

  /**
   * The session service name.
   *
   * @var string
   */
  protected $sessionServiceName;

  /**
   * Constructs a Session stack middleware object.
   *
   * @param \Symfony\Component\HttpKernel\HttpKernelInterface $http_kernel
   *   The decorated kernel.
   * @param string $service_name
   *   The name of the session service, defaults to "session".
   */
  public function __construct(HttpKernelInterface $http_kernel, $service_name = 'session') {
    $this->httpKernel = $http_kernel;
    $this->sessionServiceName = $service_name;
  }

  /**
   * {@inheritdoc}
   */
  public function handle(Request $request, $type = self::MASTER_REQUEST, $catch = TRUE) {
    if ($type === self::MASTER_REQUEST && PHP_SAPI !== 'cli') {
      $session = $this->container
        ->get($this->sessionServiceName);
      $session
        ->start();
      $request
        ->setSession($session);
    }
    $result = $this->httpKernel
      ->handle($request, $type, $catch);
    if ($type === self::MASTER_REQUEST && $request
      ->hasSession()) {
      $request
        ->getSession()
        ->save();
    }
    return $result;
  }

}

Members

Namesort descending Modifiers Type Description Overrides
ContainerAwareTrait::$container protected property
ContainerAwareTrait::setContainer public function Sets the Container associated with this Controller.
HttpKernelInterface::MASTER_REQUEST constant
HttpKernelInterface::SUB_REQUEST constant
Session::$httpKernel protected property The wrapped HTTP kernel.
Session::$sessionServiceName protected property The session service name.
Session::handle public function Handles a Request to convert it to a Response. Overrides HttpKernelInterface::handle
Session::__construct public function Constructs a Session stack middleware object.