Zend Framework  3.0
Public Member Functions | Protected Member Functions | Protected Attributes | List of all members
SessionManager Class Reference

Session ManagerInterface implementation utilizing ext/session. More...

Public Member Functions

 __construct (Config\ConfigInterface $config=null, Storage\StorageInterface $storage=null, SaveHandler\SaveHandlerInterface $saveHandler=null, array $validators=[], array $options=[])
 Constructor.
 
 sessionExists ()
 Does a session exist and is it currently active?
 
 start ($preserveStorage=false)
 Start session.
 
 destroy (array $options=null)
 Destroy/end a session.
 
 writeClose ()
 Write session to save handler and close.
 
 setName ($name)
 Attempt to set the session name.
 
 getName ()
 Get session name.
 
 setId ($id)
 Set session ID.
 
 getId ()
 Get session ID.
 
 regenerateId ($deleteOldSession=true)
 Regenerate id.
 
 rememberMe ($ttl=null)
 Set the TTL (in seconds) for the session cookie expiry.
 
 forgetMe ()
 Set a 0s TTL for the session cookie.
 
 setValidatorChain (EventManagerInterface $chain)
 Set the validator chain to use when validating a session.
 
 getValidatorChain ()
 Get the validator chain to use when validating a session.
 
 isValid ()
 Is this session valid?
 
 expireSessionCookie ()
 Expire the session cookie.
 
- Public Member Functions inherited from AbstractManager
 __construct (Config $config=null, Storage $storage=null, SaveHandler $saveHandler=null, array $validators=[])
 Constructor.
 
 setConfig (Config $config)
 Set configuration object.
 
 getConfig ()
 Retrieve configuration object.
 
 setStorage (Storage $storage)
 Set session storage object.
 
 getStorage ()
 Retrieve storage object.
 
 setSaveHandler (SaveHandler $saveHandler)
 Set session save handler object.
 
 getSaveHandler ()
 Get SaveHandler Object.
 

Protected Member Functions

 initializeValidatorChain ()
 Create validators, insert reference value and add them to the validator chain.
 
 setSessionCookieLifetime ($ttl)
 Set the session cookie lifetime.
 
 registerSaveHandler (SaveHandler\SaveHandlerInterface $saveHandler)
 Register Save Handler with ext/session.
 

Protected Attributes

 $defaultDestroyOptions
 
 $defaultOptions
 
 $defaultValidators
 
 $name
 
 $validatorChain
 
- Protected Attributes inherited from AbstractManager
 $config
 
 $defaultConfigClass = 'Zend\Session\Config\SessionConfig'
 
 $storage
 
 $defaultStorageClass = 'Zend\Session\Storage\SessionArrayStorage'
 
 $saveHandler
 
 $validators
 

Detailed Description

Session ManagerInterface implementation utilizing ext/session.

Constructor & Destructor Documentation

__construct ( Config\ConfigInterface  $config = null,
Storage\StorageInterface  $storage = null,
SaveHandler\SaveHandlerInterface  $saveHandler = null,
array  $validators = [],
array  $options = [] 
)

Constructor.

Parameters
Config\ConfigInterface | null$config
Storage\StorageInterface | null$storage
SaveHandler\SaveHandlerInterface | null$saveHandler
array$validators
array$options
Exceptions
Exception\RuntimeException

Member Function Documentation

destroy ( array  $options = null)

Destroy/end a session.

Parameters
array$optionsSee $defaultDestroyOptions
Returns
void
expireSessionCookie ( )

Expire the session cookie.

Sends a session cookie with no value, and with an expiry in the past.

Returns
void
forgetMe ( )

Set a 0s TTL for the session cookie.

Can safely be called in the middle of a session.

Returns
SessionManager
getId ( )

Get session ID.

Proxies to session_id()

Returns
string
getName ( )

Get session name.

Proxies to session_name().

Returns
string
getValidatorChain ( )

Get the validator chain to use when validating a session.

By default, uses an instance of ValidatorChain.

Returns
EventManagerInterface
initializeValidatorChain ( )
protected

Create validators, insert reference value and add them to the validator chain.

isValid ( )

Is this session valid?

Notifies the Validator Chain until either all validators have returned true or one has failed.

Returns
bool
regenerateId (   $deleteOldSession = true)

Regenerate id.

Regenerate the session ID, using session save handler's native ID generation Can safely be called in the middle of a session.

Parameters
bool$deleteOldSession
Returns
SessionManager
registerSaveHandler ( SaveHandler\SaveHandlerInterface  $saveHandler)
protected

Register Save Handler with ext/session.

Since ext/session is coupled to this particular session manager register the save handler with ext/session.

Parameters
SaveHandler\SaveHandlerInterface$saveHandler
Returns
bool
rememberMe (   $ttl = null)

Set the TTL (in seconds) for the session cookie expiry.

Can safely be called in the middle of a session.

Parameters
null | int$ttl
Returns
SessionManager
sessionExists ( )

Does a session exist and is it currently active?

Returns
bool
setId (   $id)

Set session ID.

Can safely be called in the middle of a session.

Parameters
string$id
Returns
SessionManager
setName (   $name)

Attempt to set the session name.

If the session has already been started, or if the name provided fails validation, an exception will be raised.

Parameters
string$name
Returns
SessionManager
Exceptions
Exception\InvalidArgumentException
setSessionCookieLifetime (   $ttl)
protected

Set the session cookie lifetime.

If a session already exists, destroys it (without sending an expiration cookie), regenerates the session ID, and restarts the session.

Parameters
int$ttl
Returns
void
setValidatorChain ( EventManagerInterface  $chain)

Set the validator chain to use when validating a session.

In most cases, you should use an instance of ValidatorChain.

Parameters
EventManagerInterface$chain
Returns
SessionManager
start (   $preserveStorage = false)

Start session.

if No session currently exists, attempt to start it. Calls isValid() once session_start() is called, and raises an exception if validation fails.

Parameters
bool$preserveStorageIf set to true, current session storage will not be overwritten by the contents of $_SESSION.
Returns
void
Exceptions
Exception\RuntimeException
writeClose ( )

Write session to save handler and close.

Once done, the Storage object will be marked as isImmutable.

Returns
void

Member Data Documentation

$defaultDestroyOptions
protected
Initial value:
= [
'send_expire_cookie' => true
$defaultOptions
protected
Initial value:
= [
'attach_default_validators' => true
$defaultValidators
protected
Initial value:
= [
Validator\Id::class,
]
$name
protected
$validatorChain
protected