class SessionManager extends NativeSessionStorage implements SessionManagerInterface (View source)

Manages user sessions.

This class implements the custom session management code inherited from Drupal 7 on top of the corresponding Symfony component. Regrettably the name NativeSessionStorage is not quite accurate. In fact the responsibility for storing and retrieving session data has been extracted from it in Symfony 2.1 but the class name was not changed.

In fact the NativeSessionStorage class already implements all of the functionality required by a typical Symfony application. Normally it is not necessary to subclass it at all. In order to reach the point where Drupal can use the Symfony session management unmodified, the code implemented here needs to be extracted either into a dedicated session handler proxy (e.g. sid-hashing) or relocated to the authentication subsystem.

Traits

Provides dependency injection friendly methods for serialization.

Properties

protected array $_serviceIds

An array of service IDs keyed by property name used for serialization.

from  DependencySerializationTrait
protected array $_entityStorages

An array of entity type IDs keyed by the property name of their storages.

from  DependencySerializationTrait
protected RequestStack $requestStack

The request stack.

protected Connection $connection

The database connection to use.

protected SessionConfigurationInterface $sessionConfiguration

The session configuration.

protected bool $startedLazy

Whether a lazy session has been started.

protected WriteSafeSessionHandlerInterface $writeSafeHandler

The write safe session handler.

Methods

__sleep()

{@inheritdoc}

__wakeup()

{@inheritdoc}

__construct(RequestStack $request_stack, Connection $connection, MetadataBag $metadata_bag, SessionConfigurationInterface $session_configuration, AbstractProxy|NativeSessionHandler|SessionHandlerInterface|null $handler = NULL)

Constructs a new session manager instance.

start()

{@inheritdoc}

bool
startNow()

Forcibly start a PHP session.

save()

{@inheritdoc}

regenerate($destroy = FALSE, $lifetime = NULL)

{@inheritdoc}

delete(int $uid)

Ends a specific user's session(s).

destroy()

Destroys the current session and removes session cookies.

setWriteSafeHandler(WriteSafeSessionHandlerInterface $handler)

Sets the write safe session handler.

bool
isCli()

Returns whether the current PHP process runs on CLI.

bool
isSessionObsolete()

Determines whether the session contains user data.

array
getSessionDataMask()

Returns a map specifying which session key is containing user data.

migrateStoredSession(string $old_session_id)

Migrates the current session to a new session id.

Details

__sleep()

{@inheritdoc}

__wakeup()

{@inheritdoc}

__construct(RequestStack $request_stack, Connection $connection, MetadataBag $metadata_bag, SessionConfigurationInterface $session_configuration, AbstractProxy|NativeSessionHandler|SessionHandlerInterface|null $handler = NULL)

Constructs a new session manager instance.

Parameters

RequestStack $request_stack

The request stack.

Connection $connection

The database connection.

MetadataBag $metadata_bag

The session metadata bag.

SessionConfigurationInterface $session_configuration

The session configuration interface.

AbstractProxy|NativeSessionHandler|SessionHandlerInterface|null $handler

The object to register as a PHP session handler. \Symfony\Component\HttpFoundation\Session\Storage\NativeSessionStorage::setSaveHandler()

start()

{@inheritdoc}

protected bool startNow()

Forcibly start a PHP session.

Return Value

bool

TRUE if the session is started.

save()

{@inheritdoc}

regenerate($destroy = FALSE, $lifetime = NULL)

{@inheritdoc}

Parameters

$destroy
$lifetime

delete(int $uid)

Ends a specific user's session(s).

Parameters

int $uid

User ID.

destroy()

Destroys the current session and removes session cookies.

setWriteSafeHandler(WriteSafeSessionHandlerInterface $handler)

Sets the write safe session handler.

Parameters

WriteSafeSessionHandlerInterface $handler

protected bool isCli()

Returns whether the current PHP process runs on CLI.

Command line clients do not support cookies nor sessions.

Return Value

bool

protected bool isSessionObsolete()

Determines whether the session contains user data.

Return Value

bool

TRUE when the session does not contain any values and therefore can be destroyed.

protected array getSessionDataMask()

Returns a map specifying which session key is containing user data.

Return Value

array

An array where keys correspond to the session keys and the values are booleans specifying whether the corresponding session key contains any user data.

protected migrateStoredSession(string $old_session_id)

Migrates the current session to a new session id.

Parameters

string $old_session_id

The old session ID. The new session ID is $this->getId().