From 6b24aa522409f17742ad43e2ad0fc4343479b232 Mon Sep 17 00:00:00 2001 From: cetra3 Date: Sat, 30 Aug 2014 08:48:13 +0000 Subject: [PATCH] Refactor internal session to write directly to $_SESSION --- lib/private/session/internal.php | 44 +++++++++++++++++++++++++++----- 1 file changed, 37 insertions(+), 7 deletions(-) diff --git a/lib/private/session/internal.php b/lib/private/session/internal.php index 42ec9606dc..8fda6b3b3e 100644 --- a/lib/private/session/internal.php +++ b/lib/private/session/internal.php @@ -15,46 +15,76 @@ namespace OC\Session; * * @package OC\Session */ -class Internal extends Memory { +class Internal extends Session { public function __construct($name) { session_name($name); session_start(); if (!isset($_SESSION)) { throw new \Exception('Failed to start session'); } - $this->data = $_SESSION; } public function __destruct() { $this->close(); } + /** + * @param string $key + * @param integer $value + */ + public function set($key, $value) { + $this->validateSession(); + $_SESSION[$key] = $value; + } + + /** + * @param string $key + * @return mixed + */ + public function get($key) { + if (!$this->exists($key)) { + return null; + } + return $_SESSION[$key]; + } + + /** + * @param string $key + * @return bool + */ + public function exists($key) { + return isset($_SESSION[$key]); + } + /** * @param string $key */ public function remove($key) { - // also remove it from $_SESSION to prevent re-setting the old value during the merge if (isset($_SESSION[$key])) { unset($_SESSION[$key]); } - parent::remove($key); } + public function clear() { session_unset(); @session_regenerate_id(true); @session_start(); - $this->data = $_SESSION = array(); + $_SESSION = array(); } public function close() { - $_SESSION = array_merge($_SESSION, $this->data); session_write_close(); - parent::close(); } public function reopen() { throw new \Exception('The session cannot be reopened - reopen() is ony to be used in unit testing.'); } + + private function validateSession() { + if ($this->sessionClosed) { + throw new \Exception('Session has been closed - no further changes to the session as allowed'); + } + } }