[HttpFoundation] renamed pop() to all() and getAll() to all()
This commit is contained in:
parent
0d2745f750
commit
7878a0a11a
|
@ -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
|
||||
|
|
|
@ -255,13 +255,13 @@ UPGRADE FROM 2.0 to 2.1
|
|||
|
||||
<?php if ($view['session']->getFlashes()->has('notice')): ?>
|
||||
<div class="flash-notice">
|
||||
<?php echo $view['session']->getFlashes()->pop('notice') ?>
|
||||
<?php echo $view['session']->getFlashes()->get('notice') ?>
|
||||
</div>
|
||||
<?php endif; ?>
|
||||
|
||||
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:
|
||||
|
||||
<?php foreach ($view['session']->getFlashes()->popAll() as $type => $flash): ?>
|
||||
<?php foreach ($view['session']->getFlashes()->all() as $type => $flash): ?>
|
||||
<div class="flash-$type">
|
||||
<?php echo $flash; ?>
|
||||
</div>
|
||||
|
@ -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') %}
|
||||
<div class="flash-notice">
|
||||
{{ app.session.getFlashes().pop('notice') }}
|
||||
{{ app.session.flashes.get('notice') }}
|
||||
</div>
|
||||
{% 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() %}
|
||||
<div class="flash-{{ type }}">
|
||||
{{ flashMessage }}
|
||||
</div>
|
||||
|
@ -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
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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.';
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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.
|
||||
|
|
|
@ -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());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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()
|
||||
|
|
Reference in New Issue