diff --git a/src/Symfony/Bundle/FrameworkBundle/Templating/Helper/SessionHelper.php b/src/Symfony/Bundle/FrameworkBundle/Templating/Helper/SessionHelper.php index c6628172f2..aac3f6dd7b 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Templating/Helper/SessionHelper.php +++ b/src/Symfony/Bundle/FrameworkBundle/Templating/Helper/SessionHelper.php @@ -46,9 +46,9 @@ class SessionHelper extends Helper return $this->session->get($name, $default); } - public function getFlash($name, $default = null) + public function getFlash($name, array $default = array()) { - return $this->session->getFlashBag()->get($name); + return $this->session->getFlashBag()->get($name, $default); } public function getFlashes() diff --git a/src/Symfony/Component/HttpFoundation/Session/Flash/AutoExpireFlashBag.php b/src/Symfony/Component/HttpFoundation/Session/Flash/AutoExpireFlashBag.php index 33a7835d1a..b47962fc26 100644 --- a/src/Symfony/Component/HttpFoundation/Session/Flash/AutoExpireFlashBag.php +++ b/src/Symfony/Component/HttpFoundation/Session/Flash/AutoExpireFlashBag.php @@ -139,8 +139,7 @@ class AutoExpireFlashBag implements FlashBagInterface */ public function set($type, $messages) { - $messages = (array)$messages; - $this->flashes['new'][$type] = $messages; + $this->flashes['new'][$type] = (array)$messages; } /** @@ -172,9 +171,6 @@ class AutoExpireFlashBag implements FlashBagInterface */ public function clear() { - $return = $this->all(); - $this->flashes = array('display' => array(), 'new' => array()); - - return $return; + return $this->all(); } } diff --git a/src/Symfony/Component/HttpFoundation/Session/Flash/FlashBag.php b/src/Symfony/Component/HttpFoundation/Session/Flash/FlashBag.php index de518f6ec5..6ef974ec89 100644 --- a/src/Symfony/Component/HttpFoundation/Session/Flash/FlashBag.php +++ b/src/Symfony/Component/HttpFoundation/Session/Flash/FlashBag.php @@ -121,8 +121,7 @@ class FlashBag implements FlashBagInterface */ public function set($type, $messages) { - $messages = (array)$messages; - $this->flashes[$type] = $messages; + $this->flashes[$type] = (array) $messages; } /** diff --git a/src/Symfony/Component/HttpFoundation/Session/Session.php b/src/Symfony/Component/HttpFoundation/Session/Session.php index fc89056316..ff9965e5fb 100644 --- a/src/Symfony/Component/HttpFoundation/Session/Session.php +++ b/src/Symfony/Component/HttpFoundation/Session/Session.php @@ -310,5 +310,4 @@ class Session implements SessionInterface { return $this->getBag($this->flashName)->clear(); } - } diff --git a/tests/Symfony/Tests/Component/HttpFoundation/Session/Flash/AutoExpireFlashBagTest.php b/tests/Symfony/Tests/Component/HttpFoundation/Session/Flash/AutoExpireFlashBagTest.php index f03d1885e4..d8af886afa 100644 --- a/tests/Symfony/Tests/Component/HttpFoundation/Session/Flash/AutoExpireFlashBagTest.php +++ b/tests/Symfony/Tests/Component/HttpFoundation/Session/Flash/AutoExpireFlashBagTest.php @@ -150,6 +150,6 @@ class AutoExpireFlashBagTest extends \PHPUnit_Framework_TestCase public function testClear() { - $this->assertEquals(array('notice' => 'A previous flash message'), $this->bag->clear()); + $this->assertEquals(array('notice' => array('A previous flash message')), $this->bag->clear()); } } diff --git a/tests/Symfony/Tests/Component/HttpFoundation/Session/SessionTest.php b/tests/Symfony/Tests/Component/HttpFoundation/Session/SessionTest.php index 9141c79fb9..d1e04befad 100644 --- a/tests/Symfony/Tests/Component/HttpFoundation/Session/SessionTest.php +++ b/tests/Symfony/Tests/Component/HttpFoundation/Session/SessionTest.php @@ -175,13 +175,21 @@ class SessionTest extends \PHPUnit_Framework_TestCase $this->session->setFlashes($array); $this->assertEquals($array, $this->session->getFlashes()); $this->assertEquals(array(), $this->session->getFlashes()); + $this->session->getFlashBag()->add('notice', 'foo'); + + // test that BC works by only retrieving the first added. + $this->session->getFlashBag()->add('notice', 'foo2'); + $this->assertEquals(array('notice' => 'foo'), $this->session->getFlashes()); } public function testGetSetFlash() { $this->assertNull($this->session->getFlash('notice')); $this->assertEquals('default', $this->session->getFlash('notice', 'default')); - $this->session->setFlash('notice', 'foo'); + $this->session->getFlashBag()->add('notice', 'foo'); + $this->session->getFlashBag()->add('notice', 'foo2'); + + // test that BC works by only retrieving the first added. $this->assertEquals('foo', $this->session->getFlash('notice')); $this->assertNull($this->session->getFlash('notice')); }