function SessionManager::__construct

Same name and namespace in other branches
  1. 11.x core/lib/Drupal/Core/Session/SessionManager.php \Drupal\Core\Session\SessionManager::__construct()
  2. 10 core/lib/Drupal/Core/Session/SessionManager.php \Drupal\Core\Session\SessionManager::__construct()
  3. 9 core/lib/Drupal/Core/Session/SessionManager.php \Drupal\Core\Session\SessionManager::__construct()
  4. 8.9.x core/lib/Drupal/Core/Session/SessionManager.php \Drupal\Core\Session\SessionManager::__construct()

Constructs a new session manager instance.

Parameters

\Symfony\Component\HttpFoundation\RequestStack $requestStack: The request stack.

\Symfony\Component\HttpFoundation\Session\Storage\Proxy\AbstractProxy|\SessionHandlerInterface|null $handler: The object to register as a PHP session handler.

\Drupal\Core\Session\MetadataBag $metadata_bag: The session metadata bag.

\Drupal\Core\Session\SessionConfigurationInterface $sessionConfiguration: The session configuration interface.

\Drupal\Component\Datetime\TimeInterface $time: The time service.

\Drupal\Core\Session\UserSessionRepositoryInterface $session_repository: The user session repository.

See also

\Symfony\Component\HttpFoundation\Session\Storage\NativeSessionStorage::setSaveHandler()

File

core/lib/Drupal/Core/Session/SessionManager.php, line 62

Class

SessionManager
Manages user sessions.

Namespace

Drupal\Core\Session

Code

public function __construct(protected RequestStack $requestStack, Connection|AbstractProxy|\SessionHandlerInterface|null $handler, MetadataBag $metadata_bag, protected SessionConfigurationInterface $sessionConfiguration, protected TimeInterface $time, $session_repository = NULL) {
  // The second parameter ($handler) used to be the database connection. And
  // the last parameter ($session_repository) used to be $handler. Rearrange
  // the parameters if constructor was called like this.
  if ($handler instanceof Connection && !$session_repository instanceof UserSessionRepositoryInterface) {
    @trigger_error('Calling ' . __METHOD__ . '() with a database $connection as the second argument is deprecated in drupal:11.4.0 and it will throw an error in drupal:12.0.0. See https://www.drupal.org/node/3570851', E_USER_DEPRECATED);
    $handler = $session_repository;
  }
  parent::__construct([], $handler, $metadata_bag);
  if ($session_repository instanceof UserSessionRepositoryInterface) {
    $this->sessionRepository = $session_repository;
  }
  else {
    $this->sessionRepository = \Drupal::service(UserSessionRepositoryInterface::class);
  }
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.