class Session
Same name in other branches
- 8.9.x core/lib/Drupal/Core/StackMiddleware/Session.php \Drupal\Core\StackMiddleware\Session
- 10 core/lib/Drupal/Core/StackMiddleware/Session.php \Drupal\Core\StackMiddleware\Session
- 11.x 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
- class \Drupal\Core\StackMiddleware\Session implements \Symfony\Component\HttpKernel\HttpKernelInterface uses \Symfony\Component\DependencyInjection\ContainerAwareTrait
Expanded class hierarchy of Session
38 string references to 'Session'
- AccessTest::testFileCacheability in core/
modules/ file/ tests/ src/ Kernel/ AccessTest.php - Tests cacheability metadata.
- authorize.php in core/
authorize.php - Administrative script for running authorized file operations.
- BigPipeTest::assertSessionCookieExists in core/
modules/ big_pipe/ tests/ src/ Functional/ BigPipeTest.php - Asserts whether a session cookie exists or not.
- core.services.yml in core/
core.services.yml - core/core.services.yml
- core.services.yml in core/
core.services.yml - core/core.services.yml
1 service uses Session
File
-
core/
lib/ Drupal/ Core/ StackMiddleware/ Session.php, line 17
Namespace
Drupal\Core\StackMiddlewareView 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) : Response {
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
Title Sort descending | Modifiers | Object type | Summary |
---|---|---|---|
Session::$httpKernel | protected | property | The wrapped HTTP kernel. |
Session::$sessionServiceName | protected | property | The session service name. |
Session::handle | public | function | |
Session::__construct | public | function | Constructs a Session stack middleware object. |
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.