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 |
Definition at line 35 of file Session.php.
__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 | ( | ) |
close | ( | ) |
Close session
Definition at line 140 of file Session.php.
00141 { 00142 $this->gc($this->getLifeTime()); 00143 00144 return true; 00145 }
destroy | ( | $ | sessId | ) |
Destroy session
string | $sessId |
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
int | $sessMaxLifeTime ignored |
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
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
string | $savePath ignored | |
string | $sessName ignored |
Definition at line 130 of file Session.php.
read | ( | $ | sessId | ) |
Fetch session data
string | $sessId |
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
string | $sessId | |
string | $sessData |
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 }
$_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.