[HttpFoundation] added a way to clear the session attributes
This commit is contained in:
parent
94347f73c5
commit
0fc6b15c17
@ -153,13 +153,30 @@ class Session implements \Serializable
|
|||||||
if (false === $this->started) {
|
if (false === $this->started) {
|
||||||
$this->start();
|
$this->start();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (array_key_exists($name, $this->attributes)) {
|
if (array_key_exists($name, $this->attributes)) {
|
||||||
unset($this->attributes[$name]);
|
unset($this->attributes[$name]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Clears all attributes.
|
||||||
|
*/
|
||||||
|
public function clear()
|
||||||
|
{
|
||||||
|
if (false === $this->started) {
|
||||||
|
$this->start();
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->attributes = array();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Invalidates the current session.
|
||||||
|
*/
|
||||||
public function invalidate()
|
public function invalidate()
|
||||||
{
|
{
|
||||||
|
$this->clear();
|
||||||
$this->storage->regenerate();
|
$this->storage->regenerate();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -240,7 +257,9 @@ class Session implements \Serializable
|
|||||||
public function save()
|
public function save()
|
||||||
{
|
{
|
||||||
if (true === $this->started) {
|
if (true === $this->started) {
|
||||||
|
if (isset($this->attributes['_flash'])) {
|
||||||
$this->attributes['_flash'] = array_diff_key($this->attributes['_flash'], $this->oldFlashes);
|
$this->attributes['_flash'] = array_diff_key($this->attributes['_flash'], $this->oldFlashes);
|
||||||
|
}
|
||||||
$this->storage->write('_symfony2', $this->attributes);
|
$this->storage->write('_symfony2', $this->attributes);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -149,7 +149,6 @@ class NativeSessionStorage implements SessionStorageInterface
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// regenerate a new session id once per object
|
|
||||||
session_regenerate_id($destroy);
|
session_regenerate_id($destroy);
|
||||||
|
|
||||||
self::$sessionIdRegenerated = true;
|
self::$sessionIdRegenerated = true;
|
||||||
|
Reference in New Issue
Block a user