Session
class Session implements CookieEnabledInterface (View source)
A modular session implementation based on the caching framework.
You may access the currently active session in user land code. In order to do this, inject SessionInterface and NOT just the Session object. The former will be a unique instance (singleton) representing the current session while the latter would be a completely new session instance!
You can use the Session Manager for accessing sessions which are not currently active.
Note that Flow's bootstrap (that is, Neos\Flow\Core\Scripts) will try to resume a possibly existing session automatically. If a session could be resumed during that phase already, calling start() at a later stage will be a no-operation.
Constants
private FLOW_OBJECT_STORAGE_KEY |
|
Properties
protected | $objectManager | ||
protected | $logger | ||
protected | $sessionMetaDataStore | ||
protected | $sessionKeyValueStore | ||
protected | $sessionCookieName | ||
protected | $sessionCookieLifetime | ||
protected | $sessionCookieDomain | ||
protected | $sessionCookiePath | ||
protected | $sessionCookieSecure | ||
protected | $sessionCookieHttpOnly | ||
protected | $sessionCookieSameSite | ||
protected | $sessionCookie | ||
protected | $inactivityTimeout | ||
protected | $tags | ||
protected | $now | ||
protected | $sessionMetaData | ||
protected | $started | ||
protected | $remote |
Methods
Session instances MUST NOT be created manually! They should be retrieved via the Session Manager or through dependency injection (use SessionInterface!).
No description
No description
No description
No description
Tells if the session has been started already.
Tells if the session is local (the current session bound to the current HTTP request) or remote (retrieved through the Session Manager).
Starts the session, if it has not been already started
Returns true if there is a session that can be resumed.
Resumes an existing session, if any.
Returns the current session identifier
Generates and propagates a new session ID and transfers all existing data to the new session.
Returns the data associated with the given key.
Returns true if a session data entry $key is available.
Stores the given data under the given key in the session
Returns the unix time stamp marking the last point in time this session has been in use.
Tags this session with the given tag.
Removes the specified tag from this session.
Returns the tags this session has been tagged with.
Updates the last activity time to "now".
Explicitly writes and closes the session
Explicitly destroys all session data
Shuts down this session
Automatically expires the session if the user has been inactive for too long.
Writes the cache entry containing information about the session, such as the last activity time and the storage identifier.
Details
__construct()
Session instances MUST NOT be created manually! They should be retrieved via the Session Manager or through dependency injection (use SessionInterface!).
static Session
create()
No description
static Session
createRemote(string $sessionIdentifier, string $storageIdentifier, int $lastActivityTimestamp = null, array $tags)
No description
static Session
createRemoteFromSessionMetaData(SessionMetaData $sessionMetaData)
No description
static CookieEnabledInterface
createFromCookieAndSessionInformation(Cookie $sessionCookie, string $storageIdentifier, int $lastActivityTimestamp, array $tags = [])
No description
void
injectSettings(array $settings)
No description
Cookie
getSessionCookie()
No description
bool
isStarted()
Tells if the session has been started already.
bool
isRemote()
Tells if the session is local (the current session bound to the current HTTP request) or remote (retrieved through the Session Manager).
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.
If a to-be-resumed session was inactive for too long, this function will trigger the expiration of that session. An expired session cannot be resumed.
NOTE that this method does a bit more than the name implies: Because the session info data needs to be loaded, this method stores this data already, so it doesn't have to be loaded again once the session is being used.
int|null
resume()
Resumes an existing session, if any.
string
getId()
Returns the current session identifier
string
renewId()
Generates and propagates a new session ID and transfers all existing data to the new session.
mixed
getData(string $key)
Returns the data associated with the given key.
bool
hasKey(string $key)
Returns true if a session data entry $key is available.
void
putData(string $key, mixed $data)
Stores the given data under the given key in the session
int
getLastActivityTimestamp()
Returns the unix time stamp marking the last point in time this session has been in use.
For the current (local) session, this method will always return the current time. For a remote session, the unix timestamp will be returned.
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".
void
removeTag(string $tag)
Removes the specified tag from this session.
array
getTags()
Returns the tags this session has been tagged with.
void
touch()
Updates the last activity time to "now".
void
close()
Explicitly writes and closes the session
void
destroy(string|null $reason = null)
Explicitly destroys all session data
void
shutdownObject()
Shuts down this session
This method must not be called manually – it is invoked by Flow's object management.
protected bool
autoExpire()
Automatically expires the session if the user has been inactive for too long.
protected void
writeSessionMetaDataCacheEntry()
Writes the cache entry containing information about the session, such as the last activity time and the storage identifier.
This function does not write the whole session data into the storage cache, but only the "head" cache entry containing meta information.
The session cache entry is also tagged with "session", the session identifier and any custom tags of this session, prefixed with TAG_PREFIX.