Mage_Core_Model_Mysql4_Session Class Reference

List of all members.

Public Member Functions

 __construct ()
 __destruct ()
 getLifeTime ()
 hasConnection ()
 setSaveHandler ()
 open ($savePath, $sessName)
 close ()
 read ($sessId)
 write ($sessId, $sessData)
 destroy ($sessId)
 gc ($sessMaxLifeTime)

Protected Attributes

 $_lifeTime
 $_sessionTable
 $_read
 $_write


Detailed Description

Definition at line 35 of file Session.php.


Constructor & Destructor Documentation

__construct (  ) 

Definition at line 65 of file Session.php.

00066     {
00067         $this->_sessionTable = Mage::getSingleton('core/resource')->getTableName('core/session');
00068         $this->_read = Mage::getSingleton('core/resource')->getConnection('core_read');
00069         $this->_write = Mage::getSingleton('core/resource')->getConnection('core_write');
00070     }

__destruct (  ) 

Definition at line 72 of file Session.php.

00073     {
00074         session_write_close();
00075     }


Member Function Documentation

close (  ) 

Close session

Returns:
boolean

Definition at line 140 of file Session.php.

00141     {
00142         $this->gc($this->getLifeTime());
00143 
00144         return true;
00145     }

destroy ( sessId  ) 

Destroy session

Parameters:
string $sessId
Returns:
boolean

Definition at line 200 of file Session.php.

00201     {
00202         $this->_write->query("DELETE FROM `{$this->_sessionTable}` WHERE `session_id` = ?", array($sessId));
00203         return true;
00204     }

gc ( sessMaxLifeTime  ) 

Garbage collection

Parameters:
int $sessMaxLifeTime ignored
Returns:
boolean

Definition at line 212 of file Session.php.

00213     {
00214         $this->_write->query("DELETE FROM `{$this->_sessionTable}` WHERE `session_expires` < ?", array(time()));
00215         return true;
00216     }

getLifeTime (  ) 

Definition at line 77 of file Session.php.

00078     {
00079         if (is_null($this->_lifeTime)) {
00080             $this->_lifeTime = ini_get('session.gc_maxlifetime');
00081             if (!$this->_lifeTime) {
00082                 $this->_lifeTime = 3600;
00083             }
00084         }
00085         return $this->_lifeTime;
00086     }

hasConnection (  ) 

Check DB connection

Returns:
bool

Definition at line 93 of file Session.php.

00094     {
00095         if (!$this->_read) {
00096             return false;
00097         }
00098         $tables = $this->_read->fetchAssoc('show tables');
00099         if (!isset($tables[$this->_sessionTable])) {
00100             return false;
00101         }
00102 
00103         return true;
00104     }

open ( savePath,
sessName 
)

Open session

Parameters:
string $savePath ignored
string $sessName ignored
Returns:
boolean

Definition at line 130 of file Session.php.

00131     {
00132         return true;
00133     }

read ( sessId  ) 

Fetch session data

Parameters:
string $sessId
Returns:
string

Definition at line 153 of file Session.php.

00154     {
00155         $data = $this->_read->fetchOne(
00156             "SELECT session_data FROM $this->_sessionTable
00157              WHERE session_id = ? AND session_expires > ?",
00158             array($sessId, time())
00159         );
00160 
00161         return $data;
00162     }

setSaveHandler (  ) 

Definition at line 106 of file Session.php.

00107     {
00108         if ($this->hasConnection()) {
00109             session_set_save_handler(
00110                 array($this, 'open'),
00111                 array($this, 'close'),
00112                 array($this, 'read'),
00113                 array($this, 'write'),
00114                 array($this, 'destroy'),
00115                 array($this, 'gc')
00116             );
00117         } else {
00118             session_save_path(Mage::getBaseDir('session'));
00119         }
00120         return $this;
00121     }

write ( sessId,
sessData 
)

Update session

Parameters:
string $sessId
string $sessData
Returns:
boolean

Definition at line 171 of file Session.php.

00172     {
00173         $bind = array(
00174             'session_expires'=>time() + $this->getLifeTime(),
00175             'session_data'=>$sessData
00176         );
00177 
00178         $exists = $this->_write->fetchOne(
00179             "SELECT session_id FROM `{$this->_sessionTable}`
00180              WHERE session_id = ?", array($sessId)
00181         );
00182 
00183         if ($exists) {
00184             $where = $this->_write->quoteInto('session_id=?', $sessId);
00185             $this->_write->update($this->_sessionTable, $bind, $where);
00186         } else {
00187             $bind['session_id'] = $sessId;
00188             $this->_write->insert($this->_sessionTable, $bind);
00189         }
00190 
00191         return true;
00192     }


Member Data Documentation

$_lifeTime [protected]

Definition at line 42 of file Session.php.

$_read [protected]

Definition at line 56 of file Session.php.

$_sessionTable [protected]

Definition at line 49 of file Session.php.

$_write [protected]

Definition at line 63 of file Session.php.


The documentation for this class was generated from the following file:

Generated on Sat Jul 4 17:23:59 2009 for Magento by  doxygen 1.5.8