adding an explicit close method to class session - write operations (set and remove) being called after close() will throw an exception

This commit is contained in:
Thomas Müller 2014-03-10 14:21:12 +01:00
parent 0ffd32a1ae
commit 73a1ece753
4 changed files with 20 additions and 1 deletions

View File

@ -27,7 +27,7 @@ class Internal extends Memory {
public function __destruct() {
$_SESSION = array_merge($_SESSION, $this->data);
session_write_close();
\OC::$session->close();
}
/**

View File

@ -28,6 +28,7 @@ class Memory extends Session {
* @param integer $value
*/
public function set($key, $value) {
$this->validateSession();
$this->data[$key] = $value;
}
@ -54,10 +55,17 @@ class Memory extends Session {
* @param string $key
*/
public function remove($key) {
$this->validateSession();
unset($this->data[$key]);
}
public function clear() {
$this->data = array();
}
private function validateSession() {
if ($this->sessionClosed) {
throw new \Exception('Session has been closed - no further changes to the session as allowed');
}
}
}

View File

@ -49,4 +49,10 @@ abstract class Session implements \ArrayAccess, ISession {
public function offsetUnset($offset) {
$this->remove($offset);
}
protected $sessionClosed = false;
public function close() {
$this->sessionClosed = true;
}
}

View File

@ -75,4 +75,9 @@ interface ISession {
*/
public function clear();
/**
* Close the session and release the lock
*/
public function close();
}