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
Show file Open project: appserver-io/appserver Class Usage Examples

Public Methods

Method 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

Protected Methods

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

Method Details

__construct() public method

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

checksum() public method

Returns the checksum for this session instance.
public checksum ( ) : string
return string The checksum

destroy() public method

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

emptyInstance() public static method

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

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

getDomain() public method

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

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

getLifetime() public method

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

getMaximumAge() public method

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

getName() public method

Returns the session name.
public getName ( ) : string
return string The session name

getPath() public method

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

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

init() public method

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
return void

isHttpOnly() public method

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

isSecure() public method

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

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

removeData() public method

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

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

setDomain() public method

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
return void

setHttpOnly() public method

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
return void

setId() public method

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

setLifetime() public method

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
return void

setMaximumAge() public method

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

setName() public method

Sets the session name.
public setName ( string $name ) : void
$name string The session name
return void

setPath() public method

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

setSecure() public method

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
return void

start() public method

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