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:
parent
0ffd32a1ae
commit
73a1ece753
|
@ -27,7 +27,7 @@ class Internal extends Memory {
|
|||
|
||||
public function __destruct() {
|
||||
$_SESSION = array_merge($_SESSION, $this->data);
|
||||
session_write_close();
|
||||
\OC::$session->close();
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -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');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -75,4 +75,9 @@ interface ISession {
|
|||
*/
|
||||
public function clear();
|
||||
|
||||
/**
|
||||
* Close the session and release the lock
|
||||
*/
|
||||
public function close();
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue