diff --git a/src/Symfony/Component/HttpFoundation/Session.php b/src/Symfony/Component/HttpFoundation/Session.php index 4fcefdb4c03c..2687f13fa62f 100644 --- a/src/Symfony/Component/HttpFoundation/Session.php +++ b/src/Symfony/Component/HttpFoundation/Session.php @@ -18,7 +18,7 @@ * * @author Fabien Potencier */ -class Session +class Session implements \Serializable { protected $storage; protected $locale; @@ -232,12 +232,28 @@ public function hasFlash($name) return array_key_exists($name, $this->attributes['_flash']); } - public function __destruct() + public function save() { if (true === $this->started) { $this->attributes['_flash'] = array_diff_key($this->attributes['_flash'], $this->oldFlashes); - $this->storage->write('_symfony2', $this->attributes); } } + + public function __destruct() + { + $this->save(); + } + + public function serialize() + { + return serialize(array($this->storage, $this->options)); + } + + public function unserialize($serialized) + { + list($this->storage, $this->options) = unserialize($serialized); + $this->attributes = array(); + $this->started = false; + } }