Add new method to flush session variables
This commit is contained in:
@@ -71,7 +71,7 @@ class AuthenticationManager extends Base
|
|||||||
if ($this->userSession->isLogged() ) {
|
if ($this->userSession->isLogged() ) {
|
||||||
foreach ($this->filterProviders('SessionCheckProviderInterface') as $provider) {
|
foreach ($this->filterProviders('SessionCheckProviderInterface') as $provider) {
|
||||||
if (! $provider->isValidSession()) {
|
if (! $provider->isValidSession()) {
|
||||||
unset($this->sessionStorage->user);
|
$this->sessionStorage->flush();
|
||||||
$this->preAuthentication();
|
$this->preAuthentication();
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -61,6 +61,21 @@ class SessionStorage
|
|||||||
return $session;
|
return $session;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Flush session data
|
||||||
|
*
|
||||||
|
* @access public
|
||||||
|
*/
|
||||||
|
public function flush()
|
||||||
|
{
|
||||||
|
$session = get_object_vars($this);
|
||||||
|
unset($session['storage']);
|
||||||
|
|
||||||
|
foreach (array_keys($session) as $property) {
|
||||||
|
unset($this->$property);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Copy class properties to external storage
|
* Copy class properties to external storage
|
||||||
*
|
*
|
||||||
|
|||||||
@@ -35,4 +35,26 @@ class SessionStorageTest extends Base
|
|||||||
$storage = null;
|
$storage = null;
|
||||||
$this->assertEquals(array('something' => array('a' => 'c'), 'd' => 'e'), $session);
|
$this->assertEquals(array('something' => array('a' => 'c'), 'd' => 'e'), $session);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function testFlush()
|
||||||
|
{
|
||||||
|
$session = array('d' => 'e');
|
||||||
|
|
||||||
|
$storage = new SessionStorage();
|
||||||
|
$storage->setStorage($session);
|
||||||
|
$storage->something = array('a' => 'b');
|
||||||
|
|
||||||
|
$this->assertEquals(array('a' => 'b'), $storage->something);
|
||||||
|
$this->assertEquals('e', $storage->d);
|
||||||
|
|
||||||
|
$storage->flush();
|
||||||
|
|
||||||
|
$this->assertFalse(isset($storage->d));
|
||||||
|
$this->assertFalse(isset($storage->something));
|
||||||
|
|
||||||
|
$storage->foo = 'bar';
|
||||||
|
|
||||||
|
$storage = null;
|
||||||
|
$this->assertEquals(array('foo' => 'bar'), $session);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user