PHP Class AppserverIo\Appserver\ServletEngine\Http\Session

You may access the currently active session in userland code. In order to do this, inject TYPO3\Flow\Session\SessionInterface and NOT just TYPO3\Flow\Session\Session. 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.
Inheritance: implements AppserverIo\Psr\Servlet\ServletSessionInterface
Afficher le fichier Open project: appserver-io/appserver Class Usage Examples

Méthodes publiques

Méthode Description
__construct ( mixed $id, string $name, integer | DateTime $lifetime, integer | null $maximumAge, string | null $domain, string $path, boolean $secure, boolean $httpOnly ) Constructor to initialize a newly created 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.
checksum ( ) : string Returns the checksum for this session instance.
destroy ( string $reason ) : void Explicitly destroys all session data.
emptyInstance ( ) : AppserverIo\Psr\Servlet\ServletSessionInterface Creates a new and empty session instance.
getData ( string $key ) : mixed Returns the data associated with the given key.
getDomain ( ) : string | null Returns the host to which the user agent will send this cookie.
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.
getLifetime ( ) : integer | DateTime Returns date and time after the session expires.
getMaximumAge ( ) : integer | null Returns the number of seconds until the session expires.
getName ( ) : string Returns the session name.
getPath ( ) : string Returns the path describing the scope of this cookie.
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.
init ( mixed $id, string $name, integer | DateTime $lifetime, integer | null $maximumAge, string | null $domain, string $path, boolean $secure, boolean $httpOnly, integer | null $lastActivityTimestamp = null ) : void Initializes the session with the passed data.
isHttpOnly ( ) : boolean Returns if this session should only be used through the HTTP protocol.
isSecure ( ) : boolean Returns if this session should only be sent through a "secure" channel by the user agent.
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
removeData ( string $key ) : void Removes the session data entry $key from the session.
removeTag ( string $tag ) : void Removes the specified tag from this session.
resume ( ) : integer Resumes an existing session, if any.
setDomain ( string $domain ) : void Sets the host to which the user agent will send this cookie.
setHttpOnly ( boolean $httpOnly = true ) : void Sets the flag that this session should only be used through the HTTP protocol.
setId ( string $id ) : void Sets the current session identifier.
setLifetime ( integer | DateTime $lifetime ) : void Sets date and time after the session expires.
setMaximumAge ( integer $maximumAge ) : void Sets the number of seconds until the session expires.
setName ( string $name ) : void Sets the session name.
setPath ( string $path ) : void Sets the path describing the scope of this cookie.
setSecure ( boolean $secure = true ) : void Sets the flag that this session should only be sent through a "secure" channel by the user agent.
start ( ) : void Starts the session, if it has not been already started

Méthodes protégées

Méthode Description
autoExpire ( ) : boolean Automatically expires the session if the user has been inactive for too long.

Method Details

__construct() public méthode

Constructor to initialize a newly created session.
public __construct ( mixed $id, string $name, integer | DateTime $lifetime, integer | null $maximumAge, string | null $domain, string $path, boolean $secure, boolean $httpOnly )
$id mixed The session ID
$name string The session name
$lifetime integer | DateTime Date and time after the session expires
$maximumAge integer | null Number of seconds until the session expires
$domain string | null The host to which the user agent will send this cookie
$path string The path describing the scope of this cookie
$secure boolean If this cookie should only be sent through a "secure" channel by the user agent
$httpOnly boolean If this cookie should only be used through the HTTP protocol

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 TRUE if the session can be resumed, else FALSE

checksum() public méthode

Returns the checksum for this session instance.
public checksum ( ) : string
Résultat string The checksum

destroy() public méthode

Explicitly destroys all session data.
public destroy ( string $reason ) : void
$reason string The reason why the session has been destroyed
Résultat void

emptyInstance() public static méthode

Creates a new and empty session instance.
public static emptyInstance ( ) : AppserverIo\Psr\Servlet\ServletSessionInterface
Résultat AppserverIo\Psr\Servlet\ServletSessionInterface The empty, but initialized session instance

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

getDomain() public méthode

Returns the host to which the user agent will send this cookie.
public getDomain ( ) : string | null
Résultat string | null The host to which the user agent will send this cookie

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

getLifetime() public méthode

Returns date and time after the session expires.
public getLifetime ( ) : integer | DateTime
Résultat integer | DateTime The date and time after the session expires

getMaximumAge() public méthode

Returns the number of seconds until the session expires.
public getMaximumAge ( ) : integer | null
Résultat integer | null Number of seconds until the session expires

getName() public méthode

Returns the session name.
public getName ( ) : string
Résultat string The session name

getPath() public méthode

Returns the path describing the scope of this cookie.
public getPath ( ) : string
Résultat string The path describing the scope of this cookie

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

init() public méthode

Initializes the session with the passed data.
public init ( mixed $id, string $name, integer | DateTime $lifetime, integer | null $maximumAge, string | null $domain, string $path, boolean $secure, boolean $httpOnly, integer | null $lastActivityTimestamp = null ) : void
$id mixed The session ID
$name string The session name
$lifetime integer | DateTime Date and time after the session expires
$maximumAge integer | null Number of seconds until the session expires
$domain string | null The host to which the user agent will send this cookie
$path string The path describing the scope of this cookie
$secure boolean If this cookie should only be sent through a "secure" channel by the user agent
$httpOnly boolean If this cookie should only be used through the HTTP protocol
$lastActivityTimestamp integer | null The timestamp when the session has been touched the last time
Résultat void

isHttpOnly() public méthode

Returns if this session should only be used through the HTTP protocol.
public isHttpOnly ( ) : boolean
Résultat boolean TRUE if the session should only be used through the HTTP protocol

isSecure() public méthode

Returns if this session should only be sent through a "secure" channel by the user agent.
public isSecure ( ) : boolean
Résultat boolean TRUE if the session should only be sent through a "secure" channel, else FALSE

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

removeData() public méthode

Removes the session data entry $key from the session.
public removeData ( string $key ) : void
$key string Entry identifier of the session data to remove
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

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

setDomain() public méthode

Sets the host to which the user agent will send this cookie.
public setDomain ( string $domain ) : void
$domain string The host to which the user agent will send this cookie
Résultat void

setHttpOnly() public méthode

Sets the flag that this session should only be used through the HTTP protocol.
public setHttpOnly ( boolean $httpOnly = true ) : void
$httpOnly boolean TRUE if the session should only be used through the HTTP protocol
Résultat void

setId() public méthode

Sets the current session identifier.
public setId ( string $id ) : void
$id string The current session identifier
Résultat void

setLifetime() public méthode

Sets date and time after the session expires.
public setLifetime ( integer | DateTime $lifetime ) : void
$lifetime integer | DateTime The date and time after the session expires
Résultat void

setMaximumAge() public méthode

Sets the number of seconds until the session expires.
public setMaximumAge ( integer $maximumAge ) : void
$maximumAge integer Number of seconds until the session expires
Résultat void

setName() public méthode

Sets the session name.
public setName ( string $name ) : void
$name string The session name
Résultat void

setPath() public méthode

Sets the path describing the scope of this cookie.
public setPath ( string $path ) : void
$path string The path describing the scope of this cookie
Résultat void

setSecure() public méthode

Sets the flag that this session should only be sent through a "secure" channel by the user agent.
public setSecure ( boolean $secure = true ) : void
$secure boolean TRUE if the session should only be sent through a "secure" channel, else FALSE
Résultat void

start() public méthode

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