Class THttpSession

Description

Implements interfaces:

THttpSession class

THttpSession provides session-level data management and the related configurations. To start the session, call {@open}; to complete and send out session data, call {@close}; to destroy the session, call {@destroy}. If AutoStart is true, then the session will be started once the session module is loaded and initialized.

To access data stored in session, use THttpSession like an associative array. For example,

  1. $session=new THttpSession;
  2. $session->open();
  3. $value1=$session['name1']; // get session variable 'name1'
  4. $value2=$session['name2']; // get session variable 'name2'
  5. foreach($session as $name=>$value) // traverse all session variables
  6. $session['name3']=$value3; // set session variable 'name3'

The following configurations are available for session: AutoStart, setCookie, setCacheLimiter, SavePath, UseCustomStorage, GCProbability, setCookieUsage, Timeout. See the corresponding setter and getter documentation for more information. Note, these properties must be set before the session is started.

THttpSession can be inherited with customized session storage method. Override _open, _close, _read, _write, _destroy and _gc and set UseCustomStorage to true. Then, the session data will be stored using the above methods.

By default, THttpSession is registered with TApplication as the request module. It can be accessed via TApplication::getSession().

THttpSession may be configured in application configuration file as follows,

  1. <module id="session" class="THttpSession" SessionName="SSID" SavePath="/tmp"
  2. CookieMode="Allow" UseCustomStorage="false" AutoStart="true" GCProbability="1"
  3. UseTransparentSessionID="true" TimeOut="3600" />
where SessionName, SavePath, CookieMode, UseCustomStorage, AutoStart, GCProbability, UseTransparentSessionID and getTimeOut are configurable properties of THttpSession.

  • since: 3.0
  • version: $Id: THttpSession.php 1980 2007-05-30 23:27:00Z knut $
  • author: Qiang Xue <qiang.xue@gmail.com>

Located in /Web/THttpSession.php (line 64)

TComponent
   |
   --TApplicationComponent
      |
      --THttpSession
Direct descendents
Class Description
TCacheHttpSession TCacheHttpSession class
Method Summary
void __destruct ()
void add (mixed $key, mixed $value)
void clear ()
void close ()
boolean contains (mixed $key)
integer count ()
void destroy ()
boolean getAutoStart ()
integer getCount ()
integer getGCProbability ()
string getID ()
boolean getIsStarted ()
array getKeys ()
string getSavePath ()
string getSessionID ()
string getSessionName ()
integer getTimeout ()
boolean getUseCustomStorage ()
void init (TXmlElement $config)
mixed itemAt (mixed $key)
boolean offsetExists (mixed $offset)
mixed offsetGet (integer $offset)
void offsetSet (integer $offset, mixed $item)
void offsetUnset (mixed $offset)
void open ()
mixed remove (mixed $key)
void setAutoStart (boolean $value)
void setGCProbability (integer $value)
void setID (string $value)
void setSavePath (string $value)
void setSessionID (string $value)
void setSessionName (string $value)
void setTimeout (integer $value)
void setUseCustomStorage (boolean $value)
void setUseTransparentSessionID (boolean $value)
array toArray ()
boolean _close ()
boolean _destroy (string $id)
boolean _gc (integer $maxLifetime)
boolean _open (string $savePath, string $sessionName)
string _read (string $id)
boolean _write (string $id, string $data)
Methods
Destructor __destruct (line 95)

Destructor.

Closes session.

  • access: public
void __destruct ()
add (line 523)

Adds a session variable.

Note, if the specified name already exists, the old value will be removed first.

  • access: public
void add (mixed $key, mixed $value)
  • mixed $key: session variable name
  • mixed $value: session variable value
clear (line 548)

Removes all session variables

  • access: public
void clear ()
close (line 151)

Ends the current session and store session data.

  • access: public
void close ()
contains (line 558)
  • return: whether there is the named session variable
  • access: public
boolean contains (mixed $key)
  • mixed $key: session variable name
count (line 493)

Returns the number of items in the session.

This method is required by Countable interface.

  • return: number of items in the session.
  • access: public
integer count ()
destroy (line 163)

Destroys all data registered to a session.

  • access: public
void destroy ()
getAutoStart (line 315)
  • return: whether the session should be automatically started when the session module is initialized, defaults to false.
  • access: public
boolean getAutoStart ()
getCookie (line 266)
  • return: cookie that will be used to store session ID
  • access: public
THttpCookie getCookie ()
getCookieMode (line 276)
  • return: how to use cookie to store session ID. Defaults to THttpSessionCookieMode::Allow.
  • access: public
THttpSessionCookieMode getCookieMode ()
getCount (line 483)
  • return: the number of session variables
  • access: public
integer getCount ()
getGCProbability (line 335)
  • return: the probability (percentage) that the gc (garbage collection) process is started on every session initialization, defaults to 1 meaning 1% chance.
  • access: public
integer getGCProbability ()
getID (line 104)
  • return: id of this module
  • access: public
string getID ()
getIsStarted (line 175)
  • return: whether the session has started
  • access: public
boolean getIsStarted ()
getIterator (line 475)

Returns an iterator for traversing the session variables.

This method is required by the interface IteratorAggregate.

  • return: an iterator for traversing the session variables.
  • access: public
TSessionIterator getIterator ()
getKeys (line 501)
  • return: the list of session variable names
  • access: public
array getKeys ()
getSavePath (line 225)
  • return: the current session save path, defaults to '/tmp'.
  • access: public
string getSavePath ()
getSessionID (line 183)
  • return: the current session ID
  • access: public
string getSessionID ()
getSessionName (line 203)
  • return: the current session name
  • access: public
string getSessionName ()
getTimeout (line 384)
  • return: the number of seconds after which data will be seen as 'garbage' and cleaned up, defaults to 1440 seconds.
  • access: public
integer getTimeout ()
getUseCustomStorage (line 247)
  • return: whether to use user-specified handlers to store session data. Defaults to false.
  • access: public
boolean getUseCustomStorage ()
getUseTransparentSessionID (line 365)
  • return: whether transparent sid support is enabled or not, defaults to false.
  • access: public
boolean getUseTransparentSessionID ()
init (line 123)

Initializes the module.

This method is required by IModule. If AutoStart is true, the session will be started.

  • access: public
void init (TXmlElement $config)

Redefined in descendants as:
itemAt (line 512)

Returns the session variable value with the session variable name.

This method is exactly the same as offsetGet.

  • return: the session variable value, null if no such variable exists
  • access: public
mixed itemAt (mixed $key)
  • mixed $key: the session variable name
offsetExists (line 576)

This method is required by the interface ArrayAccess.

  • access: public
boolean offsetExists (mixed $offset)
  • mixed $offset: the offset to check on
offsetGet (line 586)

This method is required by the interface ArrayAccess.

  • return: the element at the offset, null if no element is found at the offset
  • access: public
mixed offsetGet (integer $offset)
  • integer $offset: the offset to retrieve element.
offsetSet (line 596)

This method is required by the interface ArrayAccess.

  • access: public
void offsetSet (integer $offset, mixed $item)
  • integer $offset: the offset to set element
  • mixed $item: the element value
offsetUnset (line 605)

This method is required by the interface ArrayAccess.

  • access: public
void offsetUnset (mixed $offset)
  • mixed $offset: the offset to unset element
open (line 134)

Starts the session if it has not started yet.

  • access: public
void open ()
remove (line 533)

Removes a session variable.

  • return: the removed value, null if no such session variable.
  • access: public
mixed remove (mixed $key)
  • mixed $key: the name of the session variable to be removed
setAutoStart (line 324)
  • access: public
  • throws: TInvalidOperationException if session is started already
void setAutoStart (boolean $value)
  • boolean $value: whether the session should be automatically started when the session module is initialized, defaults to false.
setCookieMode (line 290)
  • access: public
  • throws: TInvalidOperationException if session is started already
void setCookieMode (THttpSessionCookieMode $value)
setGCProbability (line 345)
  • access: public
  • throws: TInvalidOperationException if session is started already
  • throws: TInvalidDataValueException if the value is beyond [0,100].
void setGCProbability (integer $value)
  • integer $value: the probability (percentage) that the gc (garbage collection) process is started on every session initialization.
setID (line 112)
  • access: public
void setID (string $value)
  • string $value: id of this module
setSavePath (line 234)
  • access: public
  • throws: TInvalidOperationException if session is started already
void setSavePath (string $value)
  • string $value: the current session save path
setSessionID (line 192)
  • access: public
  • throws: TInvalidOperationException if session is started already
void setSessionID (string $value)
  • string $value: the session ID for the current session
setSessionName (line 212)
  • access: public
  • throws: TInvalidOperationException if session is started already
void setSessionName (string $value)
  • string $value: the session name for the current session, must be an alphanumeric string, defaults to PHPSESSID
setTimeout (line 393)
  • access: public
  • throws: TInvalidOperationException if session is started already
void setTimeout (integer $value)
  • integer $value: the number of seconds after which data will be seen as 'garbage' and cleaned up
setUseCustomStorage (line 258)
  • access: public
void setUseCustomStorage (boolean $value)
  • boolean $value: whether to use user-specified handlers to store session data. If true, make sure the methods _open, _close, _read, _write, _destroy, and _gc are overridden in child class, because they will be used as the callback handlers.
setUseTransparentSessionID (line 373)
  • access: public
void setUseTransparentSessionID (boolean $value)
  • boolean $value: whether transparent sid support is enabled or not.
toArray (line 566)
  • return: the list of all session variables in array
  • access: public
array toArray ()
_close (line 418)

Session close handler.

This method should be overridden if UseCustomStorage is set true.

  • return: whether session is closed successfully
  • access: public
boolean _close ()
_destroy (line 452)

Session destroy handler.

This method should be overridden if UseCustomStorage is set true.

  • return: whether session is destroyed successfully
  • access: public
boolean _destroy (string $id)
  • string $id: session ID

Redefined in descendants as:
_gc (line 463)

Session GC (garbage collection) handler.

This method should be overridden if UseCustomStorage is set true.

  • return: whether session is GCed successfully
  • access: public
boolean _gc (integer $maxLifetime)
  • integer $maxLifetime: the number of seconds after which data will be seen as 'garbage' and cleaned up.
_open (line 408)

Session open handler.

This method should be overridden if UseCustomStorage is set true.

  • return: whether session is opened successfully
  • access: public
boolean _open (string $savePath, string $sessionName)
  • string $savePath: session save path
  • string $sessionName: session name
_read (line 429)

Session read handler.

This method should be overridden if UseCustomStorage is set true.

  • return: the session data
  • access: public
string _read (string $id)
  • string $id: session ID

Redefined in descendants as:
_write (line 441)

Session write handler.

This method should be overridden if UseCustomStorage is set true.

  • return: whether session write is successful
  • access: public
boolean _write (string $id, string $data)
  • string $id: session ID
  • string $data: session data

Redefined in descendants as:

Inherited Methods

Inherited From TApplicationComponent

TApplicationComponent::getApplication()
TApplicationComponent::getRequest()
TApplicationComponent::getResponse()
TApplicationComponent::getService()
TApplicationComponent::getSession()
TApplicationComponent::getUser()
TApplicationComponent::publishAsset()
TApplicationComponent::publishFilePath()

Inherited From TComponent

TComponent::addParsedObject()
TComponent::attachEventHandler()
TComponent::canGetProperty()
TComponent::canSetProperty()
TComponent::createdOnTemplate()
TComponent::detachEventHandler()
TComponent::evaluateExpression()
TComponent::evaluateStatements()
TComponent::getEventHandlers()
TComponent::getSubProperty()
TComponent::hasEvent()
TComponent::hasEventHandler()
TComponent::hasProperty()
TComponent::raiseEvent()
TComponent::setSubProperty()
TComponent::__get()
TComponent::__set()

Documentation generated on Sun, 30 Sep 2007 19:16:18 -0400 by phpDocumentor 1.3.0RC4