From 657885f54fdc44bd185d367d51071cd33ab61303 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Antoine=20H=C3=A9rault?= Date: Fri, 2 Dec 2011 18:00:09 +0100 Subject: [PATCH] Add the possibility to create a non-persistent flash --- src/Symfony/Component/HttpFoundation/Session.php | 14 ++++++++++---- .../Tests/Component/HttpFoundation/SessionTest.php | 10 ++++++++++ 2 files changed, 20 insertions(+), 4 deletions(-) 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')); pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

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:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy