class TransientSession implements SessionInterface (View source)

Implementation of a transient session.

This session behaves like any other session except that it only stores the data during one request.

Properties

protected string $sessionId

The session Id

protected bool $started

If this session has been started

protected array $data

The session data

protected int $lastActivityTimestamp
protected array $tags

Methods

bool
isStarted()

Tells if the session has been started already.

void
start()

Starts the session, if it has not been already started

bool
canBeResumed()

Returns true if there is a session that can be resumed. false otherwise

void
resume()

Resumes an existing session, if any.

string
renewId()

Generates and propagates a new session ID and transfers all existing data to the new session.

string
getId()

Returns the current session ID.

mixed
getData(string $key)

Returns the data associated with the given key.

bool
hasKey(string $key)

Returns true if $key is available.

void
putData(string $key, mixed $data)

Stores the given data under the given key in the session

void
close()

Closes the session

void
destroy(string $reason = null)

Explicitly destroys all session data

static void
destroyAll(Bootstrap $bootstrap)

No operation for transient session.

int
collectGarbage()

No operation for transient session.

int
getLastActivityTimestamp()

Returns the unix time stamp marking the last point in time this session has been in use.

void
touch()

Updates the last activity time to "now".

void
addTag(string $tag)

Tags this session with the given tag.

void
removeTag(string $tag)

Removes the specified tag from this session.

array
getTags()

Returns the tags this session has been tagged with.

Details

bool isStarted()

Tells if the session has been started already.

Return Value

bool

void start()

Starts the session, if it has not been already started

Return Value

void

bool canBeResumed()

Returns true if there is a session that can be resumed. false otherwise

Return Value

bool

void resume()

Resumes an existing session, if any.

Return Value

void

string renewId()

Generates and propagates a new session ID and transfers all existing data to the new session.

Return Value

string

The new session ID

string getId()

Returns the current session ID.

Return Value

string

The current session ID

Exceptions

SessionNotStartedException

mixed getData(string $key)

Returns the data associated with the given key.

Parameters

string $key

An identifier for the content stored in the session.

Return Value

mixed

The contents associated with the given key

Exceptions

SessionNotStartedException

bool hasKey(string $key)

Returns true if $key is available.

Parameters

string $key

Return Value

bool

void putData(string $key, mixed $data)

Stores the given data under the given key in the session

Parameters

string $key

The key under which the data should be stored

mixed $data

The data to be stored

Return Value

void

Exceptions

SessionNotStartedException

void close()

Closes the session

Return Value

void

Exceptions

SessionNotStartedException

void destroy(string $reason = null)

Explicitly destroys all session data

Parameters

string $reason

A reason for destroying the session – used by the LoggingAspect

Return Value

void

Exceptions

SessionNotStartedException

static void destroyAll(Bootstrap $bootstrap)

No operation for transient session.

Parameters

Bootstrap $bootstrap

Return Value

void

int collectGarbage()

No operation for transient session.

Return Value

int

The number of outdated entries removed or NULL if no such information could be determined

int getLastActivityTimestamp()

Returns the unix time stamp marking the last point in time this session has been in use.

Return Value

int

unix timestamp

void touch()

Updates the last activity time to "now".

Return Value

void

void addTag(string $tag)

Tags this session with the given tag.

Note that third-party libraries might also tag your session. Therefore it is recommended to use namespaced tags such as "Acme-Demo-MySpecialTag".

Parameters

string $tag

The tag – must match be a valid cache frontend tag

Return Value

void

Exceptions

SessionNotStartedException
InvalidArgumentException

void removeTag(string $tag)

Removes the specified tag from this session.

Parameters

string $tag

The tag – must match be a valid cache frontend tag

Return Value

void

Exceptions

SessionNotStartedException

array getTags()

Returns the tags this session has been tagged with.

Return Value

array

The tags or an empty array if there aren't any

Exceptions

SessionNotStartedException