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
Afficher le fichier Open project: neos/flow-development-collection Class Usage Examples

Protected Properties

Свойство 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

Méthodes publiques

Méthode 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".

Méthodes protégées

Méthode 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 méthode

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 méthode

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
Résultat void

autoExpire() protected méthode

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

canBeResumed() public méthode

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
Résultat boolean

close() public méthode

Explicitly writes and closes the session
public close ( ) : void
Résultat void

collectGarbage() public méthode

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

destroy() public méthode

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

getData() public méthode

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

getId() public méthode

Returns the current session identifier
public getId ( ) : string
Résultat string The current session identifier

getLastActivityTimestamp() public méthode

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
Résultat integer unix timestamp

getTags() public méthode

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

hasKey() public méthode

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

initializeHttpAndCookie() protected méthode

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

initializeObject() public méthode

public initializeObject ( ) : void
Résultat void

injectSettings() public méthode

Injects the Flow settings
public injectSettings ( array $settings ) : void
$settings array Settings of the Flow package
Résultat void

isRemote() public méthode

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
Résultat boolean TRUE if the session is remote, FALSE if this is the current session

isStarted() public méthode

Tells if the session has been started already.
public isStarted ( ) : boolean
Résultat boolean

putData() public méthode

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
Résultat void

removeSessionMetaDataCacheEntry() protected méthode

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
Résultat void

removeTag() public méthode

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

renewId() public méthode

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

resume() public méthode

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

shutdownObject() public méthode

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

start() public méthode

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

storeAuthenticatedAccountsInfo() protected méthode

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
Résultat void

touch() public méthode

Updates the last activity time to "now".
public touch ( ) : void
Résultat void

writeSessionMetaDataCacheEntry() protected méthode

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
Résultat void

Property Details

$bootstrap protected_oe property

Bootstrap for retrieving the current HTTP request
protected Bootstrap,Neos\Flow\Core $bootstrap
Résultat Neos\Flow\Core\Bootstrap

$garbageCollectionMaximumPerRun protected_oe property

protected int $garbageCollectionMaximumPerRun
Résultat integer

$garbageCollectionProbability protected_oe property

protected float $garbageCollectionProbability
Résultat float

$inactivityTimeout protected_oe property

protected int $inactivityTimeout
Résultat integer

$lastActivityTimestamp protected_oe property

protected int $lastActivityTimestamp
Résultat integer

$metaDataCache protected_oe property

Meta data cache for this session
protected VariableFrontend,Neos\Cache\Frontend $metaDataCache
Résultat Neos\Cache\Frontend\VariableFrontend

$now protected_oe property

protected int $now
Résultat integer

$objectManager protected_oe property

protected ObjectManagerInterface,Neos\Flow\ObjectManagement $objectManager
Résultat Neos\Flow\ObjectManagement\ObjectManagerInterface

$remote protected_oe property

If this session is remote or the "current" session
protected bool $remote
Résultat boolean

$request protected_oe property

protected Request,Neos\Flow\Http $request
Résultat Neos\Flow\Http\Request

$response protected_oe property

protected Response,Neos\Flow\Http $response
Résultat Neos\Flow\Http\Response

$sessionCookie protected_oe property

protected Cookie,Neos\Flow\Http $sessionCookie
Résultat Neos\Flow\Http\Cookie

$sessionCookieDomain protected_oe property

protected string $sessionCookieDomain
Résultat string

$sessionCookieHttpOnly protected_oe property

protected bool $sessionCookieHttpOnly
Résultat boolean

$sessionCookieLifetime protected_oe property

protected int $sessionCookieLifetime
Résultat integer

$sessionCookieName protected_oe property

protected string $sessionCookieName
Résultat string

$sessionCookiePath protected_oe property

protected string $sessionCookiePath
Résultat string

$sessionCookieSecure protected_oe property

protected bool $sessionCookieSecure
Résultat boolean

$sessionIdentifier protected_oe property

The session identifier
protected string $sessionIdentifier
Résultat string

$started protected_oe property

If this session has been started
protected bool $started
Résultat boolean

$storageCache protected_oe property

Storage cache for this session
protected VariableFrontend,Neos\Cache\Frontend $storageCache
Résultat Neos\Cache\Frontend\VariableFrontend

$storageIdentifier protected_oe property

Internal identifier used for storing session data in the cache
protected string $storageIdentifier
Résultat string

$systemLogger protected_oe property

protected SystemLoggerInterface,Neos\Flow\Log $systemLogger
Résultat Neos\Flow\Log\SystemLoggerInterface

$tags protected_oe property

protected array $tags
Résultat array