[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
|
* made mimetype to extension conversion configurable
|
||||||
* [BC BREAK] Moved all session related classes and interfaces into own namespace, as
|
* [BC BREAK] Moved all session related classes and interfaces into own namespace, as
|
||||||
`Symfony\Component\HttpFoudation\Session` and renamed classes accordingly.
|
`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.
|
This makes the implementation ESI compatible.
|
||||||
* Added `AutoExpireFlashBag` to replicate Symfony 2.0.x auto expire behaviour of messages auto expiring
|
* 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()`
|
* [BC BREAK] Removed the following methods from the Session class: `close()`, `setFlash()`, `setFlashes()`
|
||||||
`getFlash()`, `hasFlash()`, andd `removeFlash()`. `getFlashes() returns a `FlashBagInterface`.
|
`getFlash()`, `hasFlash()`, andd `removeFlash()`. `getFlashes() returns a `FlashBagInterface`.
|
||||||
* `Session->clear()` now only clears session attributes as before it cleared flash messages and
|
* `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
|
* Added `Symfony\Component\HttpFoundation\Session\Storage\AbstractStorage` base class for
|
||||||
session storage drivers.
|
session storage drivers.
|
||||||
* Added `Symfony\Component\HttpFoundation\Session\Storage\SaveHandlerInterface` interface
|
* 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')): ?>
|
<?php if ($view['session']->getFlashes()->has('notice')): ?>
|
||||||
<div class="flash-notice">
|
<div class="flash-notice">
|
||||||
<?php echo $view['session']->getFlashes()->pop('notice') ?>
|
<?php echo $view['session']->getFlashes()->get('notice') ?>
|
||||||
</div>
|
</div>
|
||||||
<?php endif; ?>
|
<?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">
|
<div class="flash-$type">
|
||||||
<?php echo $flash; ?>
|
<?php echo $flash; ?>
|
||||||
</div>
|
</div>
|
||||||
|
@ -277,15 +277,15 @@ UPGRADE FROM 2.0 to 2.1
|
||||||
|
|
||||||
After (Twig):
|
After (Twig):
|
||||||
|
|
||||||
{% if app.session.getFlashes().has('notice') %}
|
{% if app.session.flashes.has('notice') %}
|
||||||
<div class="flash-notice">
|
<div class="flash-notice">
|
||||||
{{ app.session.getFlashes().pop('notice') }}
|
{{ app.session.flashes.get('notice') }}
|
||||||
</div>
|
</div>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
|
||||||
Again you can process all flash messages in one go with
|
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 }}">
|
<div class="flash-{{ type }}">
|
||||||
{{ flashMessage }}
|
{{ flashMessage }}
|
||||||
</div>
|
</div>
|
||||||
|
@ -295,7 +295,7 @@ UPGRADE FROM 2.0 to 2.1
|
||||||
|
|
||||||
The methods, `setFlash()`, `setFlashes()`, `getFlash()`, `hasFlash()`, and `removeFlash()`
|
The methods, `setFlash()`, `setFlashes()`, `getFlash()`, `hasFlash()`, and `removeFlash()`
|
||||||
have been removed from the `Session` object. `getFlashes()` now returns a `FlashBagInterface`.
|
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.
|
to get all flashes in one go.
|
||||||
|
|
||||||
* Session storage drivers
|
* Session storage drivers
|
||||||
|
|
|
@ -49,12 +49,12 @@ class SessionHelper extends Helper
|
||||||
|
|
||||||
public function getFlash($type, $default = null)
|
public function getFlash($type, $default = null)
|
||||||
{
|
{
|
||||||
return $this->session->getFlashes()->pop($type);
|
return $this->session->getFlashes()->get($type);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getFlashes()
|
public function getFlashes()
|
||||||
{
|
{
|
||||||
return $this->session->getFlashes()->popAll();
|
return $this->session->getFlashes()->all();
|
||||||
}
|
}
|
||||||
|
|
||||||
public function hasFlash($type)
|
public function hasFlash($type)
|
||||||
|
|
|
@ -62,7 +62,7 @@ class SessionController extends ContainerAware
|
||||||
$session = $request->getSession();
|
$session = $request->getSession();
|
||||||
|
|
||||||
if ($session->getFlashes()->has('notice')) {
|
if ($session->getFlashes()->has('notice')) {
|
||||||
$output = $session->getFlashes()->pop('notice');
|
$output = $session->getFlashes()->get('notice');
|
||||||
} else {
|
} else {
|
||||||
$output = 'No flash was set.';
|
$output = 'No flash was set.';
|
||||||
}
|
}
|
||||||
|
|
|
@ -91,7 +91,7 @@ class AutoExpireFlashBag implements FlashBagInterface
|
||||||
/**
|
/**
|
||||||
* {@inheritdoc}
|
* {@inheritdoc}
|
||||||
*/
|
*/
|
||||||
public function pop($type, $default = null)
|
public function get($type, $default = null)
|
||||||
{
|
{
|
||||||
if (!$this->has($type)) {
|
if (!$this->has($type)) {
|
||||||
return $default;
|
return $default;
|
||||||
|
@ -113,7 +113,7 @@ class AutoExpireFlashBag implements FlashBagInterface
|
||||||
/**
|
/**
|
||||||
* {@inheritdoc}
|
* {@inheritdoc}
|
||||||
*/
|
*/
|
||||||
public function popAll()
|
public function all()
|
||||||
{
|
{
|
||||||
$return = $this->flashes['display'];
|
$return = $this->flashes['display'];
|
||||||
$this->flashes = array('new' => array(), 'display' => array());
|
$this->flashes = array('new' => array(), 'display' => array());
|
||||||
|
@ -166,7 +166,7 @@ class AutoExpireFlashBag implements FlashBagInterface
|
||||||
*/
|
*/
|
||||||
public function clear()
|
public function clear()
|
||||||
{
|
{
|
||||||
$return = $this->popAll();
|
$return = $this->all();
|
||||||
$this->flashes = array('display' => array(), 'new' => array());
|
$this->flashes = array('display' => array(), 'new' => array());
|
||||||
|
|
||||||
return $return;
|
return $return;
|
||||||
|
|
|
@ -84,13 +84,14 @@ class FlashBag implements FlashBagInterface
|
||||||
/**
|
/**
|
||||||
* {@inheritdoc}
|
* {@inheritdoc}
|
||||||
*/
|
*/
|
||||||
public function pop($type, $default = null)
|
public function get($type, $default = null)
|
||||||
{
|
{
|
||||||
if (!$this->has($type)) {
|
if (!$this->has($type)) {
|
||||||
return $default;
|
return $default;
|
||||||
}
|
}
|
||||||
|
|
||||||
$return = $this->peek($type);
|
$return = $this->flashes[$type];
|
||||||
|
|
||||||
unset($this->flashes[$type]);
|
unset($this->flashes[$type]);
|
||||||
|
|
||||||
return $return;
|
return $return;
|
||||||
|
@ -99,7 +100,7 @@ class FlashBag implements FlashBagInterface
|
||||||
/**
|
/**
|
||||||
* {@inheritdoc}
|
* {@inheritdoc}
|
||||||
*/
|
*/
|
||||||
public function popAll()
|
public function all()
|
||||||
{
|
{
|
||||||
$return = $this->peekAll();
|
$return = $this->peekAll();
|
||||||
$this->flashes = array();
|
$this->flashes = array();
|
||||||
|
@ -152,6 +153,6 @@ class FlashBag implements FlashBagInterface
|
||||||
*/
|
*/
|
||||||
public function clear()
|
public function clear()
|
||||||
{
|
{
|
||||||
return $this->popAll();
|
return $this->all();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -46,21 +46,21 @@ interface FlashBagInterface extends SessionBagInterface
|
||||||
function peekAll();
|
function peekAll();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Pops and clears flash from the stack.
|
* Gets and clears flash from the stack.
|
||||||
*
|
*
|
||||||
* @param string $type
|
* @param string $type
|
||||||
* @param string $default Default value if $type doee not exist.
|
* @param string $default Default value if $type doee not exist.
|
||||||
*
|
*
|
||||||
* @return string
|
* @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
|
* @return array
|
||||||
*/
|
*/
|
||||||
function popAll();
|
function all();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets all flash messages.
|
* 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->assertNull($this->bag->get('non_existing'));
|
||||||
$this->assertEquals('default', $this->bag->pop('non_existing', 'default'));
|
$this->assertEquals('default', $this->bag->get('non_existing', 'default'));
|
||||||
$this->assertEquals('A previous flash message', $this->bag->pop('notice'));
|
$this->assertEquals('A previous flash message', $this->bag->get('notice'));
|
||||||
$this->assertNull($this->bag->pop('notice'));
|
$this->assertNull($this->bag->get('notice'));
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testPopAll()
|
public function testAll()
|
||||||
{
|
{
|
||||||
$this->bag->set('notice', 'Foo');
|
$this->bag->set('notice', 'Foo');
|
||||||
$this->bag->set('error', 'Bar');
|
$this->bag->set('error', 'Bar');
|
||||||
$this->assertEquals(array(
|
$this->assertEquals(array(
|
||||||
'notice' => 'A previous flash message',
|
'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'));
|
$this->assertEquals('A previous flash message', $this->bag->peek('notice'));
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testPop()
|
public function testGet()
|
||||||
{
|
{
|
||||||
$this->assertNull($this->bag->pop('non_existing'));
|
$this->assertNull($this->bag->get('non_existing'));
|
||||||
$this->assertEquals('default', $this->bag->pop('not_existing', 'default'));
|
$this->assertEquals('default', $this->bag->get('not_existing', 'default'));
|
||||||
$this->assertEquals('A previous flash message', $this->bag->pop('notice'));
|
$this->assertEquals('A previous flash message', $this->bag->get('notice'));
|
||||||
$this->assertNull($this->bag->pop('notice'));
|
$this->assertNull($this->bag->get('notice'));
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testPopAll()
|
public function testAll()
|
||||||
{
|
{
|
||||||
$this->bag->set('notice', 'Foo');
|
$this->bag->set('notice', 'Foo');
|
||||||
$this->bag->set('error', 'Bar');
|
$this->bag->set('error', 'Bar');
|
||||||
$this->assertEquals(array(
|
$this->assertEquals(array(
|
||||||
'notice' => 'Foo',
|
'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()
|
public function testSet()
|
||||||
|
|
Reference in New Issue