View source
<?php
class SessionProxy_Backend_Default extends SessionProxy_Backend_Base {
protected $storage;
public function writeProxy($sessionId, $serializedData) {
if ($this
->isWriteEnabled()) {
return $this->storage
->write($sessionId, $serializedData);
}
}
public function destroyProxy($sessionId) {
$this->storage
->destroy($sessionId);
$this
->deleteCurrentSessionCookie();
$this
->refreshAfterSessionChange();
}
protected $uid;
protected function getSessionUid() {
return $this->storage
->getSessionUid();
}
protected $doWrite = TRUE;
public function writeDisable() {
$this->doWrite = FALSE;
}
public function writeEnable() {
$this->doWrite = TRUE;
}
public function isWriteEnabled() {
return $this->doWrite;
}
public function handleHttps() {
return variable_get('https', FALSE);
}
protected function sessionSetHandlers() {
if (FALSE === session_set_save_handler(array(
$this->storage,
'open',
), array(
$this->storage,
'close',
), array(
$this->storage,
'read',
), array(
$this,
'writeProxy',
), array(
$this,
'destroyProxy',
), array(
$this->storage,
'gc',
))) {
throw new Exception(__METHOD__ . ': unable to register the session handler');
}
}
public function regenerate() {
global $user;
if ($user->uid) {
$account = $user;
}
if (!$this
->sessionIsEmpty()) {
$currentData = $_SESSION;
}
if ($this->started) {
$this
->destroy();
}
$this
->generateSessionIdentifier();
if (isset($currentData) && !empty($currentData)) {
$_SESSION = $currentData;
}
$this
->start();
if (isset($account)) {
$user = $account;
}
if ($this->started) {
$params = session_get_cookie_params();
$expire = $params['lifetime'] ? REQUEST_TIME + $params['lifetime'] : 0;
setcookie($this->sessionName, $this->sessionIdentifier, $expire, $params['path'], $params['domain'], $params['secure'], $params['httponly']);
}
$this->storage
->setSessionUid($user->uid);
$this
->refreshAfterSessionChange();
}
public function destroy() {
session_destroy();
$this
->sessionSetHandlers();
$this
->deleteCurrentSessionCookie();
}
public function destroyAllForUser($uid) {
$this->storage
->destroyFor(array(
'uid',
$uid,
));
}
public function __construct(SessionProxy_Storage_Interface $storage) {
$this->storage = $storage;
$this
->sessionSetHandlers();
parent::__construct();
}
}