diff --git a/src/Symfony/Component/HttpFoundation/Session.php b/src/Symfony/Component/HttpFoundation/Session.php index 721a6c7240b99..59e6ae2bee68d 100644 --- a/src/Symfony/Component/HttpFoundation/Session.php +++ b/src/Symfony/Component/HttpFoundation/Session.php @@ -256,17 +256,23 @@ public function getFlash($name, $default = null) /** * Sets a flash message. * - * @param string $name - * @param string $value + * @param string $name + * @param string $value + * @param Boolean $persist */ - public function setFlash($name, $value) + public function setFlash($name, $value, $persist = true) { if (false === $this->started) { $this->start(); } $this->flashes[$name] = $value; - unset($this->oldFlashes[$name]); + + if ($persist) { + unset($this->oldFlashes[$name]); + } else { + $this->oldFlashes[$name] = true; + } } /** diff --git a/tests/Symfony/Tests/Component/HttpFoundation/SessionTest.php b/tests/Symfony/Tests/Component/HttpFoundation/SessionTest.php index 8318101e665d1..80e528271aec0 100644 --- a/tests/Symfony/Tests/Component/HttpFoundation/SessionTest.php +++ b/tests/Symfony/Tests/Component/HttpFoundation/SessionTest.php @@ -74,6 +74,16 @@ public function testFlashesAreFlushedWhenNeeded() $this->assertFalse($this->session->hasFlash('foo')); } + public function testNonPersistentFlashesAreFlushedWhenNeeded() + { + $this->session->setFlash('foo', 'bar', false); + $this->assertTrue($this->session->hasFlash('foo')); + $this->session->save(); + + $this->session = $this->getSession(); + $this->assertFalse($this->session->hasFlash('foo')); + } + public function testAll() { $this->assertFalse($this->session->has('foo'));
Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.
Alternative Proxies: