API Documentation

Session/SaveHandler/DbTable.php

Zend Framework

LICENSE

This source file is subject to the new BSD license that is bundled with this package in the file LICENSE.txt. It is also available through the world-wide-webat this URL: http://framework.zend.com/license/new-bsd If you did not receive a copy of the license and are unable to obtain it through the world-wide-web, please send an email to license@zend.com so we can send you a copy immediately.

category
Zend  
copyright
Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com)  
license
New BSD License  
package
Zend_Session  
version
$Id: DbTable.php 23775 2011-03-01 17:25:24Z ralph $  

\Zend_Session_SaveHandler_DbTable

Zend_Session_SaveHandler_DbTable

Extends from
\Zend_Db_Table_Abstract
Implements
\Zend_Session_SaveHandler_Interface
category
Zend  
copyright
Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com)  
license
New BSD License  
package
Zend_Session  
subpackage
SaveHandler  

Constants

Constant  PRIMARY_ASSIGNMENT = 'primaryAssignment'
Constant  PRIMARY_ASSIGNMENT_SESSION_SAVE_PATH = 'sessionSavePath'
Constant  PRIMARY_ASSIGNMENT_SESSION_NAME = 'sessionName'
Constant  PRIMARY_ASSIGNMENT_SESSION_ID = 'sessionId'
Constant  MODIFIED_COLUMN = 'modifiedColumn'
Constant  LIFETIME_COLUMN = 'lifetimeColumn'
Constant  DATA_COLUMN = 'dataColumn'
Constant  LIFETIME = 'lifetime'
Constant  OVERRIDE_LIFETIME = 'overrideLifetime'
Constant  PRIMARY_TYPE_NUM = 'PRIMARY_TYPE_NUM'
Constant  PRIMARY_TYPE_PRIMARYNUM = 'PRIMARY_TYPE_PRIMARYNUM'
Constant  PRIMARY_TYPE_ASSOC = 'PRIMARY_TYPE_ASSOC'
Constant  PRIMARY_TYPE_WHERECLAUSE = 'PRIMARY_TYPE_WHERECLAUSE'

Properties

Propertyprotectedstring  $_dataColumn= 'null'

Session table data column

Default valuenullDetails
Type
string
Propertyprotectedint  $_lifetime= 'false'

Session lifetime

Default valuefalseDetails
Type
int
Propertyprotectedstring  $_lifetimeColumn= 'null'

Session table lifetime column

Default valuenullDetails
Type
string
Propertyprotectedstring  $_modifiedColumn= 'null'

Session table last modification time column

Default valuenullDetails
Type
string
Propertyprotectedboolean  $_overrideLifetime= 'false'

Whether or not the lifetime of an existing session should be overridden

Default valuefalseDetails
Type
boolean
Propertyprotectedarray  $_primaryAssignment= 'null'

Session table primary key value assignment

Default valuenullDetails
Type
array
Propertyprotectedstring  $_sessionName= ''

Session name

Details
Type
string
Propertyprotectedstring  $_sessionSavePath= ''

Session save path

Details
Type
string

Methods

methodpublic__construct( \Zend_Config|array $config ) : void

Constructor

$config is an instance of Zend_Config or an array of key/value pairs containing configuration options for Zend_Session_SaveHandler_DbTable and Zend_Db_Table_Abstract. These are the configuration options for Zend_Session_SaveHandler_DbTable:

primaryAssignment => (string|array) Session table primary key value assignment (optional; default: 1 => sessionId) You have to assign a value to each primary key of your session table. The value of this configuration option is either a string if you have only one primary key or an array if you have multiple primary keys. The array consists of numeric keys starting at 1 and string values. There are some values which will be replaced by session information:

 sessionId       => The id of the current session
 sessionName     => The name of the current session
 sessionSavePath => The save path of the current session

 NOTE: One of your assignments MUST contain 'sessionId' as value!

modifiedColumn => (string) Session table last modification time column

lifetimeColumn => (string) Session table lifetime column

dataColumn => (string) Session table data column

lifetime => (integer) Session lifetime (optional; default: ini_get('session.gc_maxlifetime'))

overrideLifetime => (boolean) Whether or not the lifetime of an existing session should be overridden (optional; default: false)

Parameters
Name Type Description
$config \Zend_Config|array

User-provided configuration

Throws
Exception Description
\Zend_Session_SaveHandler_Exception
methodpublic__destruct( ) : void

Destructor

methodpublic_cascadeDelete( string $parentTableClassname, array $primaryKey ) : int

Called by parent table's class during delete() method.

Inherited from: \Zend_Db_Table_Abstract::_cascadeDelete()
Parameters
Name Type Description
$parentTableClassname string
$primaryKey array
Returns
Type Description
int Number of affected rows
methodpublic_cascadeUpdate( string $parentTableClassname, array $oldPrimaryKey, array $newPrimaryKey ) : int

Called by a row object for the parent table's class during save() method.

Inherited from: \Zend_Db_Table_Abstract::_cascadeUpdate()
Parameters
Name Type Description
$parentTableClassname string
$oldPrimaryKey array
$newPrimaryKey array
Returns
Type Description
int
methodprotected_checkRequiredColumns( ) : void

Check for required session table columns

Throws
Exception Description
\Zend_Session_SaveHandler_Exception
methodprotected_fetch( \Zend_Db_Table_Select $select ) : array

Support method for fetching rows.

Inherited from: \Zend_Db_Table_Abstract::_fetch()
Parameters
Name Type Description
$select \Zend_Db_Table_Select query options.
Returns
Type Description
array An array containing the row results in FETCH_ASSOC mode.
methodprotected_getCols( ) : array

Retrieve table columns

Inherited from: \Zend_Db_Table_Abstract::_getCols()
Returns
Type Description
array
methodprotected_getExpirationTime( \Zend_Db_Table_Row_Abstract $row ) : int

Retrieve session expiration time

Parameters
Name Type Description
$row \Zend_Db_Table_Row_Abstract
Returns
Type Description
int
methodprotected_getLifetime( \Zend_Db_Table_Row_Abstract $row ) : int

Retrieve session lifetime considering Zend_Session_SaveHandler_DbTable::OVERRIDE_LIFETIME

Parameters
Name Type Description
$row \Zend_Db_Table_Row_Abstract
Returns
Type Description
int
methodprotected_getPrimary( string $id, string $type = null ) : array

Retrieve session table primary key values

Parameters
Name Type Description
$id string
$type string

(optional; default: self::PRIMARY_TYPE_NUM)

Returns
Type Description
array
methodprotected_getReferenceMapNormalized( ) : array

Returns a normalized version of the reference map

Inherited from: \Zend_Db_Table_Abstract::_getReferenceMapNormalized()
Returns
Type Description
array
methodprotected_order(  $select, string|array $order ) : \Zend_Db_Table_Select

Generate ORDER clause from user-supplied string or array

Inherited from: \Zend_Db_Table_Abstract::_order()
Parameters
Name Type Description
$select
$order string|array OPTIONAL An SQL ORDER clause.
Returns
Type Description
\Zend_Db_Table_Select
methodprotected_setAdapter( mixed $db ) : \Zend_Db_Table_Abstract
Parameters
Name Type Description
$db mixed Either an Adapter object, or a string naming a Registry key
Returns
Type Description
\Zend_Db_Table_Abstract Provides a fluent interface
methodprotected_setMetadataCache( mixed $metadataCache ) : \Zend_Db_Table_Abstract

Sets the metadata cache for information returned by Zend_Db_Adapter_Abstract::describeTable().

Inherited from: \Zend_Db_Table_Abstract::_setMetadataCache()

If $metadataCache is null, then no metadata cache is used. Since there is no opportunity to reload metadata after instantiation, this method need not be public, particularly because that it would have no effect results in unnecessary API complexity. To configure the metadata cache, use the metadataCache configuration option for the class constructor upon instantiation.

Parameters
Name Type Description
$metadataCache mixed Either a Cache object, or a string naming a Registry key
Returns
Type Description
\Zend_Db_Table_Abstract Provides a fluent interface
methodprotected_setSequence( mixed $sequence ) : \Zend_Db_Table_Adapter_Abstract

Sets the sequence member, which defines the behavior for generating primary key values in new rows.

Inherited from: \Zend_Db_Table_Abstract::_setSequence()
  • If this is a string, then the string names the sequence object.
  • If this is boolean true, then the key uses an auto-incrementing or identity mechanism.
  • If this is boolean false, then the key is user-defined. Use this for natural keys, for example.
Parameters
Name Type Description
$sequence mixed
Returns
Type Description
\Zend_Db_Table_Adapter_Abstract Provides a fluent interface
methodprotected_setup( ) : void

Calls other protected methods for individual setup tasks and requirement checks

Calls other protected methods for individual tasks, to make it easier for a subclass to override part of the setup logic.

methodprotected_setupAdapter( mixed $db ) : \Zend_Db_Adapter_Abstract
Parameters
Name Type Description
$db mixed Either an Adapter object, or a string naming a Registry key
Returns
Type Description
\Zend_Db_Adapter_Abstract
Throws
Exception Description
\Zend_Db_Table_Exception
methodprotected_setupDatabaseAdapter( ) : void

Initialize database adapter.

Inherited from: \Zend_Db_Table_Abstract::_setupDatabaseAdapter()
Throws
Exception Description
\Zend_Db_Table_Exception
methodprotected_setupMetadata( ) : boolean

Initializes metadata.

Inherited from: \Zend_Db_Table_Abstract::_setupMetadata()

If metadata cannot be loaded from cache, adapter's describeTable() method is called to discover metadata information. Returns true if and only if the metadata are loaded from cache.

Returns
Type Description
boolean
Throws
Exception Description
\Zend_Db_Table_Exception
methodprotected_setupMetadataCache( mixed $metadataCache ) : \Zend_Cache_Core
Parameters
Name Type Description
$metadataCache mixed Either a Cache object, or a string naming a Registry key
Returns
Type Description
\Zend_Cache_Core
Throws
Exception Description
\Zend_Db_Table_Exception
methodprotected_setupPrimaryAssignment( ) : void

Initialize session table primary key value assignment

Throws
Exception Description
\Zend_Session_SaveHandler_Exception
methodprotected_setupPrimaryKey( ) : void

Initialize primary key from metadata.

Inherited from: \Zend_Db_Table_Abstract::_setupPrimaryKey()

If $_primary is not defined, discover primary keys from the information returned by describeTable().

Throws
Exception Description
\Zend_Db_Table_Exception
methodprotected_setupTableName( ) : void

Initialize table and schema names

If the table name is not set in the class definition, use the class name itself as the table name.

A schema name provided with the table name (e.g., "schema.table") overrides any existing value for $this->_schema.

Throws
Exception Description
\Zend_Session_SaveHandler_Exception
methodprotected_where(  $select, string|array $where ) : \Zend_Db_Table_Select

Generate WHERE clause from user-supplied string or array

Inherited from: \Zend_Db_Table_Abstract::_where()
Parameters
Name Type Description
$select
$where string|array OPTIONAL An SQL WHERE clause.
Returns
Type Description
\Zend_Db_Table_Select
methodpublicaddReference( string $ruleKey, string|array $columns, string $refTableClass, string|array $refColumns, string $onDelete = null, string $onUpdate = null ) : \Zend_Db_Table_Abstract

Add a reference to the reference map

Inherited from: \Zend_Db_Table_Abstract::addReference()
Parameters
Name Type Description
$ruleKey string
$columns string|array
$refTableClass string
$refColumns string|array
$onDelete string
$onUpdate string
Returns
Type Description
\Zend_Db_Table_Abstract
methodpublicclose( ) : boolean

Close session

Returns
Type Description
boolean
methodpubliccreateRow( array $data = array, string $defaultSource = null ) : \Zend_Db_Table_Row_Abstract

Fetches a new blank row (not from the database).

Inherited from: \Zend_Db_Table_Abstract::createRow()
Parameters
Name Type Description
$data array OPTIONAL data to populate in the new row.
$defaultSource string OPTIONAL flag to force default values into new row
Returns
Type Description
\Zend_Db_Table_Row_Abstract
methodpublicdelete( array|string $where ) : int

Deletes existing rows.

Inherited from: \Zend_Db_Table_Abstract::delete()
Parameters
Name Type Description
$where array|string

SQL WHERE clause(s).

Returns
Type Description
int The number of rows deleted.
methodpublicdestroy( string $id ) : boolean

Destroy session

Parameters
Name Type Description
$id string
Returns
Type Description
boolean
methodpublicfetchAll( string|array|\Zend_Db_Table_Select $where = null, string|array $order = null, int $count = null, int $offset = null ) : \Zend_Db_Table_Rowset_Abstract

Fetches all rows.

Inherited from: \Zend_Db_Table_Abstract::fetchAll()

Honors the Zend_Db_Adapter fetch mode.

Parameters
Name Type Description
$where string|array|\Zend_Db_Table_Select OPTIONAL An SQL WHERE clause or Zend_Db_Table_Select object.
$order string|array OPTIONAL An SQL ORDER clause.
$count int OPTIONAL An SQL LIMIT count.
$offset int OPTIONAL An SQL LIMIT offset.
Returns
Type Description
\Zend_Db_Table_Rowset_Abstract The row results per the Zend_Db_Adapter fetch mode.
methodpublicfetchNew( ) : \Zend_Db_Table_Row_Abstract

Fetches a new blank row (not from the database).

Inherited from: \Zend_Db_Table_Abstract::fetchNew()
Returns
Type Description
\Zend_Db_Table_Row_Abstract
Details
deprecated
since 0.9.3 - use createRow() instead.  
methodpublicfetchRow( string|array|\Zend_Db_Table_Select $where = null, string|array $order = null, int $offset = null ) : \Zend_Db_Table_Row_Abstract|null

Fetches one row in an object of type Zend_Db_Table_Row_Abstract, or returns null if no row matches the specified criteria.

Inherited from: \Zend_Db_Table_Abstract::fetchRow()
Parameters
Name Type Description
$where string|array|\Zend_Db_Table_Select OPTIONAL An SQL WHERE clause or Zend_Db_Table_Select object.
$order string|array OPTIONAL An SQL ORDER clause.
$offset int OPTIONAL An SQL OFFSET value.
Returns
Type Description
\Zend_Db_Table_Row_Abstractnull The row results per the Zend_Db_Adapter fetch mode, or null if no row found.
methodpublicfind( ) : \Zend_Db_Table_Rowset_Abstract

Fetches rows by primary key. The argument specifies one or more primary key value(s). To find multiple rows by primary key, the argument must be an array.

Inherited from: \Zend_Db_Table_Abstract::find()

This method accepts a variable number of arguments. If the table has a multi-column primary key, the number of arguments must be the same as the number of columns in the primary key. To find multiple rows in a table with a multi-column primary key, each argument must be an array with the same number of elements.

The find() method always returns a Rowset object, even if only one row was found.

Returns
Type Description
\Zend_Db_Table_Rowset_Abstract Row(s) matching the criteria.
Throws
Exception Description
\Zend_Db_Table_Exception
methodpublicgc( int $maxlifetime ) : true

Garbage Collection

Parameters
Name Type Description
$maxlifetime int
Returns
Type Description
true
methodpublicgetAdapter( ) : \Zend_Db_Adapter_Abstract

Gets the Zend_Db_Adapter_Abstract for this particular Zend_Db_Table object.

Inherited from: \Zend_Db_Table_Abstract::getAdapter()
Returns
Type Description
\Zend_Db_Adapter_Abstract
methodpublicgetDefaultAdapter( ) : \Zend_Db_Adapter_Abstract
static

Gets the default Zend_Db_Adapter_Abstract for all Zend_Db_Table objects.

Inherited from: \Zend_Db_Table_Abstract::getDefaultAdapter()
Returns
Type Description
\Zend_Db_Adapter_Abstract or null
methodpublicgetDefaultMetadataCache( ) : \Zend_Cache_Core
static

Gets the default metadata cache for information returned by Zend_Db_Adapter_Abstract::describeTable().

Inherited from: \Zend_Db_Table_Abstract::getDefaultMetadataCache()
Returns
Type Description
\Zend_Cache_Core or null
methodpublicgetDefaultSource( ) : \unknown

returns the default source flag that determines where defaultSources come from

Inherited from: \Zend_Db_Table_Abstract::getDefaultSource()
Returns
Type Description
\unknown
methodpublicgetDefaultValues( ) : void
methodpublicgetDefinition( ) : \Zend_Db_Table_Definition|null

getDefinition()

Inherited from: \Zend_Db_Table_Abstract::getDefinition()
Returns
Type Description
\Zend_Db_Table_Definitionnull
methodpublicgetDefinitionConfigName( ) : string

getDefinitionConfigName()

Inherited from: \Zend_Db_Table_Abstract::getDefinitionConfigName()
Returns
Type Description
string
methodpublicgetDependentTables( ) : array
Returns
Type Description
array
methodpublicgetLifetime( ) : int

Retrieve session lifetime

Returns
Type Description
int
methodpublicgetMetadataCache( ) : \Zend_Cache_Core

Gets the metadata cache for information returned by Zend_Db_Adapter_Abstract::describeTable().

Inherited from: \Zend_Db_Table_Abstract::getMetadataCache()
Returns
Type Description
\Zend_Cache_Core or null
methodpublicgetOverrideLifetime( ) : boolean

Retrieve whether or not the lifetime of an existing session should be overridden

Returns
Type Description
boolean
methodpublicgetReference( string $tableClassname, string $ruleKey = null ) : array
Parameters
Name Type Description
$tableClassname string
$ruleKey string OPTIONAL
Returns
Type Description
array
Throws
Exception Description
\Zend_Db_Table_Exception
methodpublicgetRowClass( ) : string
Returns
Type Description
string
methodpublicgetRowsetClass( ) : string
Returns
Type Description
string
methodpublicinfo( string $key = null ) : mixed

Returns table information.

Inherited from: \Zend_Db_Table_Abstract::info()

You can elect to return only a part of this information by supplying its key name, otherwise all information is returned as an array.

Parameters
Name Type Description
$key string The specific info part to return OPTIONAL
Returns
Type Description
mixed
Throws
Exception Description
\Zend_Db_Table_Exception
methodpublicinit( ) : void

Initialize object

Inherited from: \Zend_Db_Table_Abstract::init()

Called from {@link __construct()} as final step of object instantiation.

methodpublicinsert( array $data ) : mixed

Inserts a new row.

Inherited from: \Zend_Db_Table_Abstract::insert()
Parameters
Name Type Description
$data array

Column-value pairs.

Returns
Type Description
mixed The primary key of the row inserted.
methodpublicisIdentity( string $column ) : boolean

Check if the provided column is an identity of the table

Inherited from: \Zend_Db_Table_Abstract::isIdentity()
Parameters
Name Type Description
$column string
Returns
Type Description
boolean
Throws
Exception Description
\Zend_Db_Table_Exception
methodpublicmetadataCacheInClass( ) : bool

Retrieve flag indicating if metadata should be cached for duration of instance

Inherited from: \Zend_Db_Table_Abstract::metadataCacheInClass()
Returns
Type Description
bool
methodpublicopen( string $save_path, string $name ) : boolean

Open Session

Parameters
Name Type Description
$save_path string
$name string
Returns
Type Description
boolean
methodpublicread( string $id ) : string

Read session data

Parameters
Name Type Description
$id string
Returns
Type Description
string
methodpublicselect( bool $withFromPart = self ) : \Zend_Db_Table_Select

Returns an instance of a Zend_Db_Table_Select object.

Inherited from: \Zend_Db_Table_Abstract::select()
Parameters
Name Type Description
$withFromPart bool Whether or not to include the from part of the select based on the table
Returns
Type Description
\Zend_Db_Table_Select
methodpublicsetDefaultAdapter( mixed $db = null ) : void
static

Sets the default Zend_Db_Adapter_Abstract for all Zend_Db_Table objects.

Inherited from: \Zend_Db_Table_Abstract::setDefaultAdapter()
Parameters
Name Type Description
$db mixed Either an Adapter object, or a string naming a Registry key
methodpublicsetDefaultMetadataCache( mixed $metadataCache = null ) : void
static

Sets the default metadata cache for information returned by Zend_Db_Adapter_Abstract::describeTable().

Inherited from: \Zend_Db_Table_Abstract::setDefaultMetadataCache()

If $defaultMetadataCache is null, then no metadata cache is used by default.

Parameters
Name Type Description
$metadataCache mixed Either a Cache object, or a string naming a Registry key
methodpublicsetDefaultSource( string $defaultSource = self ) : \Zend_Db_Table_Abstract

set the defaultSource property - this tells the table class where to find default values

Inherited from: \Zend_Db_Table_Abstract::setDefaultSource()
Parameters
Name Type Description
$defaultSource string
Returns
Type Description
\Zend_Db_Table_Abstract
methodpublicsetDefaultValues( array $defaultValues ) : \Zend_Db_Table_Abstract

set the default values for the table class

Inherited from: \Zend_Db_Table_Abstract::setDefaultValues()
Parameters
Name Type Description
$defaultValues array
Returns
Type Description
\Zend_Db_Table_Abstract
methodpublicsetDefinition( \Zend_Db_Table_Definition $definition ) : \Zend_Db_Table_Abstract

setDefinition()

Inherited from: \Zend_Db_Table_Abstract::setDefinition()
Parameters
Name Type Description
$definition \Zend_Db_Table_Definition
Returns
Type Description
\Zend_Db_Table_Abstract
methodpublicsetDefinitionConfigName(  $definitionConfigName ) : \Zend_Db_Table_Abstract

setDefinitionConfigName()

Inherited from: \Zend_Db_Table_Abstract::setDefinitionConfigName()
Parameters
Name Type Description
$definitionConfigName
Returns
Type Description
\Zend_Db_Table_Abstract
methodpublicsetDependentTables( array $dependentTables ) : \Zend_Db_Table_Abstract
Parameters
Name Type Description
$dependentTables array
Returns
Type Description
\Zend_Db_Table_Abstract Provides a fluent interface
methodpublicsetLifetime( int $lifetime, boolean $overrideLifetime = null ) : \Zend_Session_SaveHandler_DbTable

Set session lifetime and optional whether or not the lifetime of an existing session should be overridden

$lifetime === false resets lifetime to session.gc_maxlifetime

Parameters
Name Type Description
$lifetime int
$overrideLifetime boolean

(optional)

Returns
Type Description
\Zend_Session_SaveHandler_DbTable
methodpublicsetMetadataCacheInClass( bool $flag ) : \Zend_Db_Table_Abstract

Indicate whether metadata should be cached in the class for the duration of the instance

Inherited from: \Zend_Db_Table_Abstract::setMetadataCacheInClass()
Parameters
Name Type Description
$flag bool
Returns
Type Description
\Zend_Db_Table_Abstract
methodpublicsetOptions( array $options ) : \Zend_Db_Table_Abstract

setOptions()

Inherited from: \Zend_Db_Table_Abstract::setOptions()
Parameters
Name Type Description
$options array
Returns
Type Description
\Zend_Db_Table_Abstract
methodpublicsetOverrideLifetime( boolean $overrideLifetime ) : \Zend_Session_SaveHandler_DbTable

Set whether or not the lifetime of an existing session should be overridden

Parameters
Name Type Description
$overrideLifetime boolean
Returns
Type Description
\Zend_Session_SaveHandler_DbTable
methodpublicsetReferences( array $referenceMap ) : \Zend_Db_Table_Abstract
Parameters
Name Type Description
$referenceMap array
Returns
Type Description
\Zend_Db_Table_Abstract Provides a fluent interface
methodpublicsetRowClass( string $classname ) : \Zend_Db_Table_Abstract
Parameters
Name Type Description
$classname string
Returns
Type Description
\Zend_Db_Table_Abstract Provides a fluent interface
methodpublicsetRowsetClass( string $classname ) : \Zend_Db_Table_Abstract
Parameters
Name Type Description
$classname string
Returns
Type Description
\Zend_Db_Table_Abstract Provides a fluent interface
methodpublicupdate( array $data, array|string $where ) : int

Updates existing rows.

Inherited from: \Zend_Db_Table_Abstract::update()
Parameters
Name Type Description
$data array

Column-value pairs.

$where array|string An SQL WHERE clause, or an array of SQL WHERE clauses.
Returns
Type Description
int The number of rows updated.
methodpublicwrite( string $id, string $data ) : boolean

Write session data

Parameters
Name Type Description
$id string
$data string
Returns
Type Description
boolean
Documentation was generated by DocBlox 0.13.3.