Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

updating session with delete and end #68

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 13 additions & 1 deletion docs/Session.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 5 additions & 1 deletion src/EpiSession.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,14 +48,18 @@ 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'))
{
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))
Expand Down
9 changes: 9 additions & 0 deletions src/EpiSession_Apc.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
9 changes: 9 additions & 0 deletions src/EpiSession_Memcached.php
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand Down
9 changes: 9 additions & 0 deletions src/EpiSession_Php.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,15 @@
<?php
class EpiSession_Php implements EpiSessionInterface
{
public function delete($key = null)
{
if ($this->get($key) === false)
return false;

unset($_SESSION[$key]);
return true;
}

public function end()
{
$_SESSION = array();
Expand Down