From 7878a0a11aef9e0865ff5e68959a7cfa66a5d28e Mon Sep 17 00:00:00 2001 From: Fabien Potencier Date: Sat, 11 Feb 2012 11:45:20 +0100 Subject: [PATCH] [HttpFoundation] renamed pop() to all() and getAll() to all() --- CHANGELOG-2.1.md | 6 +++--- UPGRADE-2.1.md | 14 +++++++------- .../Templating/Helper/SessionHelper.php | 4 ++-- .../TestBundle/Controller/SessionController.php | 2 +- .../Session/Flash/AutoExpireFlashBag.php | 6 +++--- .../HttpFoundation/Session/Flash/FlashBag.php | 9 +++++---- .../Session/Flash/FlashBagInterface.php | 8 ++++---- .../Session/Flash/AutoExpireFlashBagTest.php | 16 ++++++++-------- .../Session/Flash/FlashBagTest.php | 16 ++++++++-------- 9 files changed, 41 insertions(+), 40 deletions(-) diff --git a/CHANGELOG-2.1.md b/CHANGELOG-2.1.md index 69e632d86f..b08ac98781 100644 --- a/CHANGELOG-2.1.md +++ b/CHANGELOG-2.1.md @@ -231,14 +231,14 @@ To get the diff between two versions, go to https://github.com/symfony/symfony/c * made mimetype to extension conversion configurable * [BC BREAK] Moved all session related classes and interfaces into own namespace, as `Symfony\Component\HttpFoudation\Session` and renamed classes accordingly. - * Added `FlashBag` (default). Flashes expire when retrieved by `pop()` or `popAll()`. + * Added `FlashBag` (default). Flashes expire when retrieved by `get()` or `all()`. This makes the implementation ESI compatible. * Added `AutoExpireFlashBag` to replicate Symfony 2.0.x auto expire behaviour of messages auto expiring - after one page page load. Messages must be retrived by `pop()` or `popAll()`. + after one page page load. Messages must be retrived by `get()` or `all()`. * [BC BREAK] Removed the following methods from the Session class: `close()`, `setFlash()`, `setFlashes()` `getFlash()`, `hasFlash()`, andd `removeFlash()`. `getFlashes() returns a `FlashBagInterface`. * `Session->clear()` now only clears session attributes as before it cleared flash messages and - attributes. `Session->getFlashes()->popAll()` clears flashes now. + attributes. `Session->getFlashes()->all()` clears flashes now. * Added `Symfony\Component\HttpFoundation\Session\Storage\AbstractStorage` base class for session storage drivers. * Added `Symfony\Component\HttpFoundation\Session\Storage\SaveHandlerInterface` interface diff --git a/UPGRADE-2.1.md b/UPGRADE-2.1.md index 76204f8bfd..641c967c96 100644 --- a/UPGRADE-2.1.md +++ b/UPGRADE-2.1.md @@ -255,13 +255,13 @@ UPGRADE FROM 2.0 to 2.1 getFlashes()->has('notice')): ?>
- getFlashes()->pop('notice') ?> + getFlashes()->get('notice') ?>
- If you wanted to process all flash types you could also make use of the `getFlashes()->popAll()` API: + If you wanted to process all flash types you could also make use of the `getFlashes()->all()` API: - getFlashes()->popAll() as $type => $flash): ?> + getFlashes()->all() as $type => $flash): ?>
@@ -277,15 +277,15 @@ UPGRADE FROM 2.0 to 2.1 After (Twig): - {% if app.session.getFlashes().has('notice') %} + {% if app.session.flashes.has('notice') %}
- {{ app.session.getFlashes().pop('notice') }} + {{ app.session.flashes.get('notice') }}
{% endif %} Again you can process all flash messages in one go with - {% for type, flashMessage in app.session.getFlashes().popAll() %} + {% for type, flashMessage in app.session.flashes.all() %}
{{ flashMessage }}
@@ -295,7 +295,7 @@ UPGRADE FROM 2.0 to 2.1 The methods, `setFlash()`, `setFlashes()`, `getFlash()`, `hasFlash()`, and `removeFlash()` have been removed from the `Session` object. `getFlashes()` now returns a `FlashBagInterface`. - Flashes should be popped off the stack using `getFlashes()->pop()` or `getFlashes()->popAll()` + Flashes should be popped off the stack using `getFlashes()->get()` or `getFlashes()->all()` to get all flashes in one go. * Session storage drivers diff --git a/src/Symfony/Bundle/FrameworkBundle/Templating/Helper/SessionHelper.php b/src/Symfony/Bundle/FrameworkBundle/Templating/Helper/SessionHelper.php index 15e25c460d..4a7842efd9 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Templating/Helper/SessionHelper.php +++ b/src/Symfony/Bundle/FrameworkBundle/Templating/Helper/SessionHelper.php @@ -49,12 +49,12 @@ class SessionHelper extends Helper public function getFlash($type, $default = null) { - return $this->session->getFlashes()->pop($type); + return $this->session->getFlashes()->get($type); } public function getFlashes() { - return $this->session->getFlashes()->popAll(); + return $this->session->getFlashes()->all(); } public function hasFlash($type) 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 0a1aa0c66c..626c2e2cbd 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->getFlashes()->has('notice')) { - $output = $session->getFlashes()->pop('notice'); + $output = $session->getFlashes()->get('notice'); } else { $output = 'No flash was set.'; } diff --git a/src/Symfony/Component/HttpFoundation/Session/Flash/AutoExpireFlashBag.php b/src/Symfony/Component/HttpFoundation/Session/Flash/AutoExpireFlashBag.php index 39c068edcb..1c7b9e9d07 100644 --- a/src/Symfony/Component/HttpFoundation/Session/Flash/AutoExpireFlashBag.php +++ b/src/Symfony/Component/HttpFoundation/Session/Flash/AutoExpireFlashBag.php @@ -91,7 +91,7 @@ class AutoExpireFlashBag implements FlashBagInterface /** * {@inheritdoc} */ - public function pop($type, $default = null) + public function get($type, $default = null) { if (!$this->has($type)) { return $default; @@ -113,7 +113,7 @@ class AutoExpireFlashBag implements FlashBagInterface /** * {@inheritdoc} */ - public function popAll() + public function all() { $return = $this->flashes['display']; $this->flashes = array('new' => array(), 'display' => array()); @@ -166,7 +166,7 @@ class AutoExpireFlashBag implements FlashBagInterface */ public function clear() { - $return = $this->popAll(); + $return = $this->all(); $this->flashes = array('display' => array(), 'new' => array()); return $return; diff --git a/src/Symfony/Component/HttpFoundation/Session/Flash/FlashBag.php b/src/Symfony/Component/HttpFoundation/Session/Flash/FlashBag.php index 1ec7175847..cbb77af03d 100644 --- a/src/Symfony/Component/HttpFoundation/Session/Flash/FlashBag.php +++ b/src/Symfony/Component/HttpFoundation/Session/Flash/FlashBag.php @@ -84,13 +84,14 @@ class FlashBag implements FlashBagInterface /** * {@inheritdoc} */ - public function pop($type, $default = null) + public function get($type, $default = null) { if (!$this->has($type)) { return $default; } - $return = $this->peek($type); + $return = $this->flashes[$type]; + unset($this->flashes[$type]); return $return; @@ -99,7 +100,7 @@ class FlashBag implements FlashBagInterface /** * {@inheritdoc} */ - public function popAll() + public function all() { $return = $this->peekAll(); $this->flashes = array(); @@ -152,6 +153,6 @@ class FlashBag implements FlashBagInterface */ public function clear() { - return $this->popAll(); + return $this->all(); } } diff --git a/src/Symfony/Component/HttpFoundation/Session/Flash/FlashBagInterface.php b/src/Symfony/Component/HttpFoundation/Session/Flash/FlashBagInterface.php index 5cca797f7d..0c45d74bb7 100644 --- a/src/Symfony/Component/HttpFoundation/Session/Flash/FlashBagInterface.php +++ b/src/Symfony/Component/HttpFoundation/Session/Flash/FlashBagInterface.php @@ -46,21 +46,21 @@ interface FlashBagInterface extends SessionBagInterface function peekAll(); /** - * Pops and clears flash from the stack. + * Gets and clears flash from the stack. * * @param string $type * @param string $default Default value if $type doee not exist. * * @return string */ - function pop($type, $default = null); + function get($type, $default = null); /** - * Pops and clears flashes from the stack. + * Gets and clears flashes from the stack. * * @return array */ - function popAll(); + function all(); /** * Sets all flash messages. diff --git a/tests/Symfony/Tests/Component/HttpFoundation/Session/Flash/AutoExpireFlashBagTest.php b/tests/Symfony/Tests/Component/HttpFoundation/Session/Flash/AutoExpireFlashBagTest.php index a81017c677..3b12c0eaea 100644 --- a/tests/Symfony/Tests/Component/HttpFoundation/Session/Flash/AutoExpireFlashBagTest.php +++ b/tests/Symfony/Tests/Component/HttpFoundation/Session/Flash/AutoExpireFlashBagTest.php @@ -108,23 +108,23 @@ class AutoExpireFlashBagTest extends \PHPUnit_Framework_TestCase ); } - public function testPop() + public function testGet() { - $this->assertNull($this->bag->pop('non_existing')); - $this->assertEquals('default', $this->bag->pop('non_existing', 'default')); - $this->assertEquals('A previous flash message', $this->bag->pop('notice')); - $this->assertNull($this->bag->pop('notice')); + $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')); } - public function testPopAll() + public function testAll() { $this->bag->set('notice', 'Foo'); $this->bag->set('error', 'Bar'); $this->assertEquals(array( 'notice' => 'A previous flash message', - ), $this->bag->popAll() + ), $this->bag->all() ); - $this->assertEquals(array(), $this->bag->popAll()); + $this->assertEquals(array(), $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 524106f509..3616ec9156 100644 --- a/tests/Symfony/Tests/Component/HttpFoundation/Session/Flash/FlashBagTest.php +++ b/tests/Symfony/Tests/Component/HttpFoundation/Session/Flash/FlashBagTest.php @@ -63,24 +63,24 @@ class FlashBagTest extends \PHPUnit_Framework_TestCase $this->assertEquals('A previous flash message', $this->bag->peek('notice')); } - public function testPop() + public function testGet() { - $this->assertNull($this->bag->pop('non_existing')); - $this->assertEquals('default', $this->bag->pop('not_existing', 'default')); - $this->assertEquals('A previous flash message', $this->bag->pop('notice')); - $this->assertNull($this->bag->pop('notice')); + $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')); } - public function testPopAll() + public function testAll() { $this->bag->set('notice', 'Foo'); $this->bag->set('error', 'Bar'); $this->assertEquals(array( 'notice' => 'Foo', - 'error' => 'Bar'), $this->bag->popAll() + 'error' => 'Bar'), $this->bag->all() ); - $this->assertEquals(array(), $this->bag->popAll()); + $this->assertEquals(array(), $this->bag->all()); } public function testSet()