From 1367776c769c784cac093d9df68a7b29c583b228 Mon Sep 17 00:00:00 2001 From: Geo Miller Date: Mon, 29 Jul 2013 18:43:51 -0400 Subject: [PATCH] updating session with delete and end --- docs/Session.markdown | 14 +++++++++++++- src/EpiSession.php | 6 +++++- src/EpiSession_Apc.php | 9 +++++++++ src/EpiSession_Memcached.php | 9 +++++++++ src/EpiSession_Php.php | 9 +++++++++ 5 files changed, 45 insertions(+), 2 deletions(-) diff --git a/docs/Session.markdown b/docs/Session.markdown index 0747b1c..d7a12d2 100644 --- a/docs/Session.markdown +++ b/docs/Session.markdown @@ -29,12 +29,24 @@ To specify which session driver to use you should pass the appropriate value to ### Available methods -The available methods are `get`, `set` and `end`. +The available methods are `get`, `set` `delete` and `end`. + +Get the value of a key $name: get($name); + +Set the key $name to $value: + set($name, $value); + +Delete the key $name: + delete($name); +Remove and destroy all session variables: + + end(); + ---------------------------------------- ### Requirement for using Memcached diff --git a/src/EpiSession.php b/src/EpiSession.php index ff001da..7f4712d 100644 --- a/src/EpiSession.php +++ b/src/EpiSession.php @@ -48,6 +48,8 @@ interface EpiSessionInterface { public function get($key = null); public function set($key = null, $value = null); + public function delete($key = null); + public function end(); } if(!function_exists('getSession')) @@ -55,7 +57,9 @@ public function set($key = null, $value = null); function getSession() { $employ = EpiSession::employ(); - $class = array_shift($employ); + $class = ""; + if($employ) + $class = array_shift($employ); if($employ && class_exists($class)) return EpiSession::getInstance($class, $employ); elseif(class_exists(EpiSession::PHP)) diff --git a/src/EpiSession_Apc.php b/src/EpiSession_Apc.php index 65e10ea..3dad4e0 100644 --- a/src/EpiSession_Apc.php +++ b/src/EpiSession_Apc.php @@ -4,6 +4,15 @@ class EpiSession_Apc implements EpiSessionInterface private $key = null; private $store= null; + public function delete($key = null) + { + if($this->get($key) === false) + return false; + + unset($this->store[$key]); + return apc_store($this->key, $this->store); + } + public function end() { apc_delete($this->key); diff --git a/src/EpiSession_Memcached.php b/src/EpiSession_Memcached.php index 8ecdae1..afd1ea6 100644 --- a/src/EpiSession_Memcached.php +++ b/src/EpiSession_Memcached.php @@ -19,6 +19,15 @@ public function __construct($params = array()) $this->expiry = !empty($params[3]) ? $params[3] : 3600; } + public function delete($key = null) + { + if ($this->get($key) === false) + return false; + + unset($this->store[$key]); + return $this->memcached->set($this->key, $this->store); + } + public function end() { if(!$this->connect()) diff --git a/src/EpiSession_Php.php b/src/EpiSession_Php.php index e1ab103..015399f 100644 --- a/src/EpiSession_Php.php +++ b/src/EpiSession_Php.php @@ -1,6 +1,15 @@ get($key) === false) + return false; + + unset($_SESSION[$key]); + return true; + } + public function end() { $_SESSION = array();