PHP Class Neos\Flow\Session\Session

You may access the currently active session in userland 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.
See also: SessionManager
Inheritance: implements Neos\Flow\Session\SessionInterface
Exibir arquivo Open project: neos/flow-development-collection Class Usage Examples

Protected Properties

Property Type Description
$bootstrap Neos\Flow\Core\Bootstrap Bootstrap for retrieving the current HTTP request
$garbageCollectionMaximumPerRun integer
$garbageCollectionProbability float
$inactivityTimeout integer
$lastActivityTimestamp integer
$metaDataCache Neos\Cache\Frontend\VariableFrontend Meta data cache for this session
$now integer
$objectManager Neos\Flow\ObjectManagement\ObjectManagerInterface
$remote boolean If this session is remote or the "current" session
$request Neos\Flow\Http\Request
$response Neos\Flow\Http\Response
$sessionCookie Neos\Flow\Http\Cookie
$sessionCookieDomain string
$sessionCookieHttpOnly boolean
$sessionCookieLifetime integer
$sessionCookieName string
$sessionCookiePath string
$sessionCookieSecure boolean
$sessionIdentifier string The session identifier
$started boolean If this session has been started
$storageCache Neos\Cache\Frontend\VariableFrontend Storage cache for this session
$storageIdentifier string Internal identifier used for storing session data in the cache
$systemLogger Neos\Flow\Log\SystemLoggerInterface
$tags array

Public Methods

Method Description
__construct ( string $sessionIdentifier = null, string $storageIdentifier = null, integer $lastActivityTimestamp = null, array $tags = [] ) Constructs this session
addTag ( string $tag ) : void Tags this session with the given tag.
canBeResumed ( ) : boolean Returns TRUE if there is a session that can be resumed.
close ( ) : void Explicitly writes and closes the session
collectGarbage ( ) : integer Iterates over all existing sessions and removes their data if the inactivity timeout was reached.
destroy ( string $reason = null ) : void Explicitly destroys all session data
getData ( string $key ) : mixed Returns the data associated with the given key.
getId ( ) : string Returns the current session identifier
getLastActivityTimestamp ( ) : integer Returns the unix time stamp marking the last point in time this session has been in use.
getTags ( ) : array Returns the tags this session has been tagged with.
hasKey ( string $key ) : boolean Returns TRUE if a session data entry $key is available.
initializeObject ( ) : void
injectSettings ( array $settings ) : void Injects the Flow settings
isRemote ( ) : boolean Tells if the session is local (the current session bound to the current HTTP request) or remote (retrieved through the Session Manager).
isStarted ( ) : boolean Tells if the session has been started already.
putData ( string $key, mixed $data ) : void Stores the given data under the given key in the session
removeTag ( string $tag ) : void Removes the specified tag from this session.
renewId ( ) : string Generates and propagates a new session ID and transfers all existing data to the new session.
resume ( ) : integer Resumes an existing session, if any.
shutdownObject ( ) : void Shuts down this session
start ( ) : void Starts the session, if it has not been already started
touch ( ) : void Updates the last activity time to "now".

Protected Methods

Method Description
autoExpire ( ) : boolean Automatically expires the session if the user has been inactive for too long.
initializeHttpAndCookie ( Neos\Flow\Http\HttpRequestHandlerInterface $requestHandler ) : void Initialize request, response and session cookie
removeSessionMetaDataCacheEntry ( string $sessionIdentifier ) : void Removes the session info cache entry for the specified session.
storeAuthenticatedAccountsInfo ( array $tokens ) : void Stores some information about the authenticated accounts in the session data.
writeSessionMetaDataCacheEntry ( ) : void Writes the cache entry containing information about the session, such as the last activity time and the storage identifier.

Method Details

__construct() public method

If $sessionIdentifier is specified, this constructor will create a session instance representing a remote session. In that case $storageIdentifier and $lastActivityTimestamp are also required arguments. Session instances MUST NOT be created manually! They should be retrieved via the Session Manager or through dependency injection (use SessionInterface!).
public __construct ( string $sessionIdentifier = null, string $storageIdentifier = null, integer $lastActivityTimestamp = null, array $tags = [] )
$sessionIdentifier string The public session identifier which is also used in the session cookie
$storageIdentifier string The private storage identifier which is used for storage cache entries
$lastActivityTimestamp integer Unix timestamp of the last known activity for this session
$tags array A list of tags set for this session

addTag() public method

Note that third-party libraries might also tag your session. Therefore it is recommended to use namespaced tags such as "Acme-Demo-MySpecialTag".
public addTag ( string $tag ) : void
$tag string The tag – must match be a valid cache frontend tag
return void

autoExpire() protected method

Automatically expires the session if the user has been inactive for too long.
protected autoExpire ( ) : boolean
return boolean TRUE if the session expired, FALSE if not

canBeResumed() public method

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.
public canBeResumed ( ) : boolean
return boolean

close() public method

Explicitly writes and closes the session
public close ( ) : void
return void

collectGarbage() public method

Iterates over all existing sessions and removes their data if the inactivity timeout was reached.
public collectGarbage ( ) : integer
return integer The number of outdated entries removed

destroy() public method

Explicitly destroys all session data
public destroy ( string $reason = null ) : void
$reason string A reason for destroying the session – used by the LoggingAspect
return void

getData() public method

Returns the data associated with the given key.
public getData ( string $key ) : mixed
$key string An identifier for the content stored in the session.
return mixed The contents associated with the given key

getId() public method

Returns the current session identifier
public getId ( ) : string
return string The current session identifier

getLastActivityTimestamp() public method

For the current (local) session, this method will always return the current time. For a remote session, the unix timestamp will be returned.
public getLastActivityTimestamp ( ) : integer
return integer unix timestamp

getTags() public method

Returns the tags this session has been tagged with.
public getTags ( ) : array
return array The tags or an empty array if there aren't any

hasKey() public method

Returns TRUE if a session data entry $key is available.
public hasKey ( string $key ) : boolean
$key string Entry identifier of the session data
return boolean

initializeHttpAndCookie() protected method

Initialize request, response and session cookie
protected initializeHttpAndCookie ( Neos\Flow\Http\HttpRequestHandlerInterface $requestHandler ) : void
$requestHandler Neos\Flow\Http\HttpRequestHandlerInterface
return void

initializeObject() public method

public initializeObject ( ) : void
return void

injectSettings() public method

Injects the Flow settings
public injectSettings ( array $settings ) : void
$settings array Settings of the Flow package
return void

isRemote() public method

Tells if the session is local (the current session bound to the current HTTP request) or remote (retrieved through the Session Manager).
public isRemote ( ) : boolean
return boolean TRUE if the session is remote, FALSE if this is the current session

isStarted() public method

Tells if the session has been started already.
public isStarted ( ) : boolean
return boolean

putData() public method

Stores the given data under the given key in the session
public putData ( string $key, mixed $data ) : void
$key string The key under which the data should be stored
$data mixed The data to be stored
return void

removeSessionMetaDataCacheEntry() protected method

Note that this function does only remove the "head" cache entry, not the related data referred to by the storage identifier.
protected removeSessionMetaDataCacheEntry ( string $sessionIdentifier ) : void
$sessionIdentifier string
return void

removeTag() public method

Removes the specified tag from this session.
public removeTag ( string $tag ) : void
$tag string The tag – must match be a valid cache frontend tag
return void

renewId() public method

Generates and propagates a new session ID and transfers all existing data to the new session.
public renewId ( ) : string
return string The new session ID

resume() public method

Resumes an existing session, if any.
public resume ( ) : integer
return integer If a session was resumed, the inactivity of since the last request is returned

shutdownObject() public method

This method must not be called manually – it is invoked by Flow's object management.
public shutdownObject ( ) : void
return void

start() public method

Starts the session, if it has not been already started
public start ( ) : void
return void

storeAuthenticatedAccountsInfo() protected method

This method will check if a session has already been started, which is the case after tokens relying on a session have been authenticated: the UsernamePasswordToken does, for example, start a session in its authenticate() method. Because more than one account can be authenticated at a time, this method accepts an array of tokens instead of a single account. Note that if a session is started after tokens have been authenticated, the session will NOT be tagged with authenticated accounts.
protected storeAuthenticatedAccountsInfo ( array $tokens ) : void
$tokens array
return void

touch() public method

Updates the last activity time to "now".
public touch ( ) : void
return void

writeSessionMetaDataCacheEntry() protected method

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.
protected writeSessionMetaDataCacheEntry ( ) : void
return void

Property Details

$bootstrap protected_oe property

Bootstrap for retrieving the current HTTP request
protected Bootstrap,Neos\Flow\Core $bootstrap
return Neos\Flow\Core\Bootstrap

$garbageCollectionMaximumPerRun protected_oe property

protected int $garbageCollectionMaximumPerRun
return integer

$garbageCollectionProbability protected_oe property

protected float $garbageCollectionProbability
return float

$inactivityTimeout protected_oe property

protected int $inactivityTimeout
return integer

$lastActivityTimestamp protected_oe property

protected int $lastActivityTimestamp
return integer

$metaDataCache protected_oe property

Meta data cache for this session
protected VariableFrontend,Neos\Cache\Frontend $metaDataCache
return Neos\Cache\Frontend\VariableFrontend

$now protected_oe property

protected int $now
return integer

$objectManager protected_oe property

protected ObjectManagerInterface,Neos\Flow\ObjectManagement $objectManager
return Neos\Flow\ObjectManagement\ObjectManagerInterface

$remote protected_oe property

If this session is remote or the "current" session
protected bool $remote
return boolean

$request protected_oe property

protected Request,Neos\Flow\Http $request
return Neos\Flow\Http\Request

$response protected_oe property

protected Response,Neos\Flow\Http $response
return Neos\Flow\Http\Response

$sessionCookie protected_oe property

protected Cookie,Neos\Flow\Http $sessionCookie
return Neos\Flow\Http\Cookie

$sessionCookieDomain protected_oe property

protected string $sessionCookieDomain
return string

$sessionCookieHttpOnly protected_oe property

protected bool $sessionCookieHttpOnly
return boolean

$sessionCookieLifetime protected_oe property

protected int $sessionCookieLifetime
return integer

$sessionCookieName protected_oe property

protected string $sessionCookieName
return string

$sessionCookiePath protected_oe property

protected string $sessionCookiePath
return string

$sessionCookieSecure protected_oe property

protected bool $sessionCookieSecure
return boolean

$sessionIdentifier protected_oe property

The session identifier
protected string $sessionIdentifier
return string

$started protected_oe property

If this session has been started
protected bool $started
return boolean

$storageCache protected_oe property

Storage cache for this session
protected VariableFrontend,Neos\Cache\Frontend $storageCache
return Neos\Cache\Frontend\VariableFrontend

$storageIdentifier protected_oe property

Internal identifier used for storing session data in the cache
protected string $storageIdentifier
return string

$systemLogger protected_oe property

protected SystemLoggerInterface,Neos\Flow\Log $systemLogger
return Neos\Flow\Log\SystemLoggerInterface

$tags protected_oe property

protected array $tags
return array