diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/Functional/Bundle/TestBundle/Controller/SessionController.php b/src/Symfony/Bundle/FrameworkBundle/Tests/Functional/Bundle/TestBundle/Controller/SessionController.php index b1c4334cde..5b45131e29 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Tests/Functional/Bundle/TestBundle/Controller/SessionController.php +++ b/src/Symfony/Bundle/FrameworkBundle/Tests/Functional/Bundle/TestBundle/Controller/SessionController.php @@ -62,7 +62,7 @@ class SessionController extends ContainerAware $session = $request->getSession(); if ($session->getFlashBag()->has('notice')) { - $output = $session->getFlashBag()->get('notice'); + list($output) = $session->getFlashBag()->get('notice'); } else { $output = 'No flash was set.'; } diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/Templating/Helper/SessionHelperTest.php b/src/Symfony/Bundle/FrameworkBundle/Tests/Templating/Helper/SessionHelperTest.php index ce8c91b173..e73445d211 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Tests/Templating/Helper/SessionHelperTest.php +++ b/src/Symfony/Bundle/FrameworkBundle/Tests/Templating/Helper/SessionHelperTest.php @@ -42,13 +42,13 @@ class SessionHelperTest extends \PHPUnit_Framework_TestCase $this->assertTrue($helper->hasFlash('notice')); - $this->assertEquals('bar', $helper->getFlash('notice')); + $this->assertEquals(array('bar'), $helper->getFlash('notice')); } public function testGetFlashes() { $helper = new SessionHelper($this->request); - $this->assertEquals(array('notice' => 'bar'), $helper->getFlashes()); + $this->assertEquals(array('notice' => array('bar')), $helper->getFlashes()); } public function testGet() diff --git a/src/Symfony/Component/HttpFoundation/Session/Flash/AutoExpireFlashBag.php b/src/Symfony/Component/HttpFoundation/Session/Flash/AutoExpireFlashBag.php index 10257847e8..33a7835d1a 100644 --- a/src/Symfony/Component/HttpFoundation/Session/Flash/AutoExpireFlashBag.php +++ b/src/Symfony/Component/HttpFoundation/Session/Flash/AutoExpireFlashBag.php @@ -75,7 +75,15 @@ class AutoExpireFlashBag implements FlashBagInterface /** * {@inheritdoc} */ - public function peek($type, $default = null) + public function add($type, $message) + { + $this->flashes['new'][$type][] = $message; + } + + /** + * {@inheritdoc} + */ + public function peek($type, array $default = array()) { return $this->has($type) ? $this->flashes['display'][$type] : $default; } @@ -91,7 +99,7 @@ class AutoExpireFlashBag implements FlashBagInterface /** * {@inheritdoc} */ - public function get($type, $default = null) + public function get($type, array $default = array()) { $return = $default; @@ -129,9 +137,10 @@ class AutoExpireFlashBag implements FlashBagInterface /** * {@inheritdoc} */ - public function set($type, $message) + public function set($type, $messages) { - $this->flashes['new'][$type] = $message; + $messages = (array)$messages; + $this->flashes['new'][$type] = $messages; } /** @@ -139,7 +148,7 @@ class AutoExpireFlashBag implements FlashBagInterface */ public function has($type) { - return array_key_exists($type, $this->flashes['display']); + return array_key_exists($type, $this->flashes['display']) && $this->flashes['display'][$type]; } /** diff --git a/src/Symfony/Component/HttpFoundation/Session/Flash/FlashBag.php b/src/Symfony/Component/HttpFoundation/Session/Flash/FlashBag.php index c0b4ee57a0..de518f6ec5 100644 --- a/src/Symfony/Component/HttpFoundation/Session/Flash/FlashBag.php +++ b/src/Symfony/Component/HttpFoundation/Session/Flash/FlashBag.php @@ -68,7 +68,15 @@ class FlashBag implements FlashBagInterface /** * {@inheritdoc} */ - public function peek($type, $default = null) + public function add($type, $message) + { + $this->flashes[$type][] = $message; + } + + /** + * {@inheritdoc} + */ + public function peek($type, array $default =array()) { return $this->has($type) ? $this->flashes[$type] : $default; } @@ -84,7 +92,7 @@ class FlashBag implements FlashBagInterface /** * {@inheritdoc} */ - public function get($type, $default = null) + public function get($type, array $default = array()) { if (!$this->has($type)) { return $default; @@ -111,9 +119,10 @@ class FlashBag implements FlashBagInterface /** * {@inheritdoc} */ - public function set($type, $message) + public function set($type, $messages) { - $this->flashes[$type] = $message; + $messages = (array)$messages; + $this->flashes[$type] = $messages; } /** @@ -129,7 +138,7 @@ class FlashBag implements FlashBagInterface */ public function has($type) { - return array_key_exists($type, $this->flashes); + return array_key_exists($type, $this->flashes) && $this->flashes[$type]; } /** diff --git a/src/Symfony/Component/HttpFoundation/Session/Flash/FlashBagInterface.php b/src/Symfony/Component/HttpFoundation/Session/Flash/FlashBagInterface.php index 0c45d74bb7..48ccf05f00 100644 --- a/src/Symfony/Component/HttpFoundation/Session/Flash/FlashBagInterface.php +++ b/src/Symfony/Component/HttpFoundation/Session/Flash/FlashBagInterface.php @@ -32,11 +32,11 @@ interface FlashBagInterface extends SessionBagInterface * Gets flash message for a given type. * * @param string $type Message category type. - * @param string $default Default value if $type doee not exist. + * @param array $default Default value if $type doee not exist. * * @return string */ - function peek($type, $default = null); + function peek($type, array $default = array()); /** * Gets all flash messages. @@ -49,11 +49,11 @@ interface FlashBagInterface extends SessionBagInterface * Gets and clears flash from the stack. * * @param string $type - * @param string $default Default value if $type doee not exist. + * @param array $default Default value if $type doee not exist. * * @return string */ - function get($type, $default = null); + function get($type, array $default = array()); /** * Gets and clears flashes from the stack. diff --git a/tests/Symfony/Tests/Component/HttpFoundation/Session/Flash/AutoExpireFlashBagTest.php b/tests/Symfony/Tests/Component/HttpFoundation/Session/Flash/AutoExpireFlashBagTest.php index c2b34c5611..f03d1885e4 100644 --- a/tests/Symfony/Tests/Component/HttpFoundation/Session/Flash/AutoExpireFlashBagTest.php +++ b/tests/Symfony/Tests/Component/HttpFoundation/Session/Flash/AutoExpireFlashBagTest.php @@ -34,7 +34,7 @@ class AutoExpireFlashBagTest extends \PHPUnit_Framework_TestCase { parent::setUp(); $this->bag = new FlashBag(); - $this->array = array('new' => array('notice' => 'A previous flash message')); + $this->array = array('new' => array('notice' => array('A previous flash message'))); $this->bag->initialize($this->array); } @@ -47,16 +47,16 @@ class AutoExpireFlashBagTest extends \PHPUnit_Framework_TestCase public function testInitialize() { $bag = new FlashBag(); - $array = array('new' => array('notice' => 'A previous flash message')); + $array = array('new' => array('notice' => array('A previous flash message'))); $bag->initialize($array); - $this->assertEquals('A previous flash message', $bag->peek('notice')); + $this->assertEquals(array('A previous flash message'), $bag->peek('notice')); $array = array('new' => array( - 'notice' => 'Something else', - 'error' => 'a', + 'notice' => array('Something else'), + 'error' => array('a'), )); $bag->initialize($array); - $this->assertEquals('Something else', $bag->peek('notice')); - $this->assertEquals('a', $bag->peek('error')); + $this->assertEquals(array('Something else'), $bag->peek('notice')); + $this->assertEquals(array('a'), $bag->peek('error')); } public function testGetStorageKey() @@ -75,16 +75,16 @@ class AutoExpireFlashBagTest extends \PHPUnit_Framework_TestCase public function testPeek() { - $this->assertNull($this->bag->peek('non_existing')); - $this->assertEquals('default', $this->bag->peek('non_existing', 'default')); - $this->assertEquals('A previous flash message', $this->bag->peek('notice')); - $this->assertEquals('A previous flash message', $this->bag->peek('notice')); + $this->assertEquals(array(), $this->bag->peek('non_existing')); + $this->assertEquals(array('default'), $this->bag->peek('non_existing', array('default'))); + $this->assertEquals(array('A previous flash message'), $this->bag->peek('notice')); + $this->assertEquals(array('A previous flash message'), $this->bag->peek('notice')); } public function testSet() { $this->bag->set('notice', 'Foo'); - $this->assertNotEquals('Foo', $this->bag->peek('notice')); + $this->assertEquals(array('A previous flash message'), $this->bag->peek('notice')); } public function testHas() @@ -123,10 +123,10 @@ class AutoExpireFlashBagTest extends \PHPUnit_Framework_TestCase public function testGet() { - $this->assertNull($this->bag->get('non_existing')); - $this->assertEquals('default', $this->bag->get('non_existing', 'default')); - $this->assertEquals('A previous flash message', $this->bag->get('notice')); - $this->assertNull($this->bag->get('notice')); + $this->assertEquals(array(), $this->bag->get('non_existing')); + $this->assertEquals(array('default'), $this->bag->get('non_existing', array('default'))); + $this->assertEquals(array('A previous flash message'), $this->bag->get('notice')); + $this->assertEquals(array(), $this->bag->get('notice')); } public function testSetAll() @@ -141,7 +141,7 @@ class AutoExpireFlashBagTest extends \PHPUnit_Framework_TestCase $this->bag->set('notice', 'Foo'); $this->bag->set('error', 'Bar'); $this->assertEquals(array( - 'notice' => 'A previous flash message', + 'notice' => array('A previous flash message'), ), $this->bag->all() ); diff --git a/tests/Symfony/Tests/Component/HttpFoundation/Session/Flash/FlashBagTest.php b/tests/Symfony/Tests/Component/HttpFoundation/Session/Flash/FlashBagTest.php index 1ae73f8f0a..35197b0e35 100644 --- a/tests/Symfony/Tests/Component/HttpFoundation/Session/Flash/FlashBagTest.php +++ b/tests/Symfony/Tests/Component/HttpFoundation/Session/Flash/FlashBagTest.php @@ -35,7 +35,7 @@ class FlashBagTest extends \PHPUnit_Framework_TestCase { parent::setUp(); $this->bag = new FlashBag(); - $this->array = array('notice' => 'A previous flash message'); + $this->array = array('notice' => array('A previous flash message')); $this->bag->initialize($this->array); } @@ -71,18 +71,18 @@ class FlashBagTest extends \PHPUnit_Framework_TestCase public function testPeek() { - $this->assertNull($this->bag->peek('non_existing')); - $this->assertEquals('default', $this->bag->peek('not_existing', 'default')); - $this->assertEquals('A previous flash message', $this->bag->peek('notice')); - $this->assertEquals('A previous flash message', $this->bag->peek('notice')); + $this->assertEquals(array(), $this->bag->peek('non_existing')); + $this->assertEquals(array('default'), $this->bag->peek('not_existing', array('default'))); + $this->assertEquals(array('A previous flash message'), $this->bag->peek('notice')); + $this->assertEquals(array('A previous flash message'), $this->bag->peek('notice')); } public function testGet() { - $this->assertNull($this->bag->get('non_existing')); - $this->assertEquals('default', $this->bag->get('not_existing', 'default')); - $this->assertEquals('A previous flash message', $this->bag->get('notice')); - $this->assertNull($this->bag->get('notice')); + $this->assertEquals(array(), $this->bag->get('non_existing')); + $this->assertEquals(array('default'), $this->bag->get('not_existing', array('default'))); + $this->assertEquals(array('A previous flash message'), $this->bag->get('notice')); + $this->assertEquals(array(), $this->bag->get('notice')); } public function testAll() @@ -90,8 +90,8 @@ class FlashBagTest extends \PHPUnit_Framework_TestCase $this->bag->set('notice', 'Foo'); $this->bag->set('error', 'Bar'); $this->assertEquals(array( - 'notice' => 'Foo', - 'error' => 'Bar'), $this->bag->all() + 'notice' => array('Foo'), + 'error' => array('Bar')), $this->bag->all() ); $this->assertEquals(array(), $this->bag->all()); @@ -101,7 +101,7 @@ class FlashBagTest extends \PHPUnit_Framework_TestCase { $this->bag->set('notice', 'Foo'); $this->bag->set('notice', 'Bar'); - $this->assertEquals('Bar', $this->bag->peek('notice')); + $this->assertEquals(array('Bar'), $this->bag->peek('notice')); } public function testHas() @@ -120,15 +120,15 @@ class FlashBagTest extends \PHPUnit_Framework_TestCase $this->bag->set('notice', 'Foo'); $this->bag->set('error', 'Bar'); $this->assertEquals(array( - 'notice' => 'Foo', - 'error' => 'Bar', + 'notice' => array('Foo'), + 'error' => array('Bar'), ), $this->bag->peekAll() ); $this->assertTrue($this->bag->has('notice')); $this->assertTrue($this->bag->has('error')); $this->assertEquals(array( - 'notice' => 'Foo', - 'error' => 'Bar', + 'notice' => array('Foo'), + 'error' => array('Bar'), ), $this->bag->peekAll() ); } diff --git a/tests/Symfony/Tests/Component/HttpFoundation/Session/Storage/MockFileSessionStorageTest.php b/tests/Symfony/Tests/Component/HttpFoundation/Session/Storage/MockFileSessionStorageTest.php index c0453df977..3212939de8 100644 --- a/tests/Symfony/Tests/Component/HttpFoundation/Session/Storage/MockFileSessionStorageTest.php +++ b/tests/Symfony/Tests/Component/HttpFoundation/Session/Storage/MockFileSessionStorageTest.php @@ -81,7 +81,7 @@ class MockFileSessionStorageTest extends \PHPUnit_Framework_TestCase $storage->start(); $this->assertEquals('108', $storage->getBag('attributes')->get('new')); $this->assertTrue($storage->getBag('flashes')->has('newkey')); - $this->assertEquals('test', $storage->getBag('flashes')->peek('newkey')); + $this->assertEquals(array('test'), $storage->getBag('flashes')->peek('newkey')); } public function testMultipleInstances()