renamed getFlashes() to getFlashBag() to avoid clashes
This commit is contained in:
parent
282d3ae1d8
commit
8a01dd5cff
@ -231,9 +231,9 @@ To get the diff between two versions, go to https://github.com/symfony/symfony/c
|
||||
* Added `AutoExpireFlashBag` (default) to replicate Symfony 2.0.x auto expire behaviour of messages auto expiring
|
||||
after one page page load. Messages must be retrived by `get()` or `all()`.
|
||||
* Deprecated the following methods from the Session class: `close()`, `setFlash()`, `setFlashes()`
|
||||
`getFlash()`, `hasFlash()`, and `removeFlash()`. Use `getFlashes() instead which returns a `FlashBagInterface`.
|
||||
`getFlash()`, `hasFlash()`, and `removeFlash()`. Use `getFlashBag() instead which returns a `FlashBagInterface`.
|
||||
* `Session->clear()` now only clears session attributes as before it cleared flash messages and
|
||||
attributes. `Session->getFlashes()->all()` clears flashes now.
|
||||
attributes. `Session->getFlashBag()->all()` clears flashes now.
|
||||
* Added `Symfony\Component\HttpFoundation\Session\Storage\AbstractSessionStorage` base class for
|
||||
session storage drivers.
|
||||
* Added `Symfony\Component\HttpFoundation\Session\Storage\SessionSaveHandlerInterface` interface
|
||||
|
@ -268,15 +268,15 @@ UPGRADE FROM 2.0 to 2.1
|
||||
|
||||
After (PHP):
|
||||
|
||||
<?php if ($view['session']->getFlashes()->has('notice')): ?>
|
||||
<?php if ($view['session']->getFlashBag()->has('notice')): ?>
|
||||
<div class="flash-notice">
|
||||
<?php echo $view['session']->getFlashes()->get('notice') ?>
|
||||
<?php echo $view['session']->getFlashBag()->get('notice') ?>
|
||||
</div>
|
||||
<?php endif; ?>
|
||||
|
||||
If you wanted to process all flash types you could also make use of the `getFlashes()->all()` API:
|
||||
If you wanted to process all flash types you could also make use of the `getFlashBag()->all()` API:
|
||||
|
||||
<?php foreach ($view['session']->getFlashes()->all() as $type => $flash): ?>
|
||||
<?php foreach ($view['session']->getFlashBag()->all() as $type => $flash): ?>
|
||||
<div class="flash-$type">
|
||||
<?php echo $flash; ?>
|
||||
</div>
|
||||
|
@ -48,17 +48,17 @@ class SessionHelper extends Helper
|
||||
|
||||
public function getFlash($name, $default = null)
|
||||
{
|
||||
return $this->session->getFlashes()->get($name);
|
||||
return $this->session->getFlashBag()->get($name);
|
||||
}
|
||||
|
||||
public function getFlashes()
|
||||
{
|
||||
return $this->session->getFlashes()->all();
|
||||
return $this->session->getFlashBag()->all();
|
||||
}
|
||||
|
||||
public function hasFlash($name)
|
||||
{
|
||||
return $this->session->getFlashes()->has($name);
|
||||
return $this->session->getFlashBag()->has($name);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -51,7 +51,7 @@ class SessionController extends ContainerAware
|
||||
{
|
||||
$request = $this->container->get('request');
|
||||
$session = $request->getSession();
|
||||
$session->getFlashes()->set('notice', $message);
|
||||
$session->getFlashBag()->set('notice', $message);
|
||||
|
||||
return new RedirectResponse($this->container->get('router')->generate('session_showflash'));
|
||||
}
|
||||
@ -61,8 +61,8 @@ class SessionController extends ContainerAware
|
||||
$request = $this->container->get('request');
|
||||
$session = $request->getSession();
|
||||
|
||||
if ($session->getFlashes()->has('notice')) {
|
||||
$output = $session->getFlashes()->get('notice');
|
||||
if ($session->getFlashBag()->has('notice')) {
|
||||
$output = $session->getFlashBag()->get('notice');
|
||||
} else {
|
||||
$output = 'No flash was set.';
|
||||
}
|
||||
|
@ -26,7 +26,7 @@ class SessionHelperTest extends \PHPUnit_Framework_TestCase
|
||||
|
||||
$session = new Session(new MockArraySessionStorage());
|
||||
$session->set('foobar', 'bar');
|
||||
$session->getFlashes()->set('notice', 'bar');
|
||||
$session->getFlashBag()->set('notice', 'bar');
|
||||
|
||||
$this->request->setSession($session);
|
||||
}
|
||||
|
@ -15,6 +15,7 @@ use Symfony\Component\DependencyInjection\ContainerAware;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
use Symfony\Component\HttpFoundation\RedirectResponse;
|
||||
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
|
||||
use Symfony\Component\HttpFoundation\Session\Flash\AutoExpireFlashBag;
|
||||
|
||||
/**
|
||||
* ProfilerController.
|
||||
@ -146,9 +147,9 @@ class ProfilerController extends ContainerAware
|
||||
{
|
||||
$request = $this->container->get('request');
|
||||
|
||||
if (null !== $session = $request->getSession()) {
|
||||
// keep current flashes for one more request
|
||||
$session->setFlashes($session->getFlashes());
|
||||
if (null !== $session = $request->getSession() && $session instanceof AutoExpireFlashBag) {
|
||||
// keep current flashes for one more request if using AutoExpireFlashBag
|
||||
$session->getFlashBag()->setAll($session->getFlashBag()->peekAll());
|
||||
}
|
||||
|
||||
if (null === $token) {
|
||||
|
@ -74,9 +74,7 @@ class WebDebugToolbarListener
|
||||
$session = $request->getSession();
|
||||
if ($session instanceof AutoExpireFlashBag) {
|
||||
// keep current flashes for one more request if using AutoExpireFlashBag
|
||||
foreach ($session->getFlashKeys() as $type) {
|
||||
$session->setFlashes($session->getFlashes($type));
|
||||
}
|
||||
$session->getFlashBag()->setAll($session->getFlashBag()->peekAll());
|
||||
}
|
||||
|
||||
$response->setContent($this->templating->render('WebProfilerBundle:Profiler:toolbar_redirect.html.twig', array('location' => $response->headers->get('Location'))));
|
||||
|
@ -241,7 +241,7 @@ class Session implements SessionInterface
|
||||
*
|
||||
* @return FlashBagInterface
|
||||
*/
|
||||
public function getFlashes()
|
||||
public function getFlashBag()
|
||||
{
|
||||
return $this->getBag('flashes');
|
||||
}
|
||||
|
Reference in New Issue
Block a user