renamed getFlashes() to getFlashBag() to avoid clashes

This commit is contained in:
Fabien Potencier 2012-02-11 13:09:41 +01:00
parent 282d3ae1d8
commit 8a01dd5cff
8 changed files with 19 additions and 20 deletions

View File

@ -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 * 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()`. after one page page load. Messages must be retrived by `get()` or `all()`.
* Deprecated the following methods from the Session class: `close()`, `setFlash()`, `setFlashes()` * 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 * `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 * Added `Symfony\Component\HttpFoundation\Session\Storage\AbstractSessionStorage` base class for
session storage drivers. session storage drivers.
* Added `Symfony\Component\HttpFoundation\Session\Storage\SessionSaveHandlerInterface` interface * Added `Symfony\Component\HttpFoundation\Session\Storage\SessionSaveHandlerInterface` interface

View File

@ -268,15 +268,15 @@ UPGRADE FROM 2.0 to 2.1
After (PHP): After (PHP):
<?php if ($view['session']->getFlashes()->has('notice')): ?> <?php if ($view['session']->getFlashBag()->has('notice')): ?>
<div class="flash-notice"> <div class="flash-notice">
<?php echo $view['session']->getFlashes()->get('notice') ?> <?php echo $view['session']->getFlashBag()->get('notice') ?>
</div> </div>
<?php endif; ?> <?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"> <div class="flash-$type">
<?php echo $flash; ?> <?php echo $flash; ?>
</div> </div>

View File

@ -48,17 +48,17 @@ class SessionHelper extends Helper
public function getFlash($name, $default = null) public function getFlash($name, $default = null)
{ {
return $this->session->getFlashes()->get($name); return $this->session->getFlashBag()->get($name);
} }
public function getFlashes() public function getFlashes()
{ {
return $this->session->getFlashes()->all(); return $this->session->getFlashBag()->all();
} }
public function hasFlash($name) public function hasFlash($name)
{ {
return $this->session->getFlashes()->has($name); return $this->session->getFlashBag()->has($name);
} }
/** /**

View File

@ -51,7 +51,7 @@ class SessionController extends ContainerAware
{ {
$request = $this->container->get('request'); $request = $this->container->get('request');
$session = $request->getSession(); $session = $request->getSession();
$session->getFlashes()->set('notice', $message); $session->getFlashBag()->set('notice', $message);
return new RedirectResponse($this->container->get('router')->generate('session_showflash')); return new RedirectResponse($this->container->get('router')->generate('session_showflash'));
} }
@ -61,8 +61,8 @@ class SessionController extends ContainerAware
$request = $this->container->get('request'); $request = $this->container->get('request');
$session = $request->getSession(); $session = $request->getSession();
if ($session->getFlashes()->has('notice')) { if ($session->getFlashBag()->has('notice')) {
$output = $session->getFlashes()->get('notice'); $output = $session->getFlashBag()->get('notice');
} else { } else {
$output = 'No flash was set.'; $output = 'No flash was set.';
} }

View File

@ -26,7 +26,7 @@ class SessionHelperTest extends \PHPUnit_Framework_TestCase
$session = new Session(new MockArraySessionStorage()); $session = new Session(new MockArraySessionStorage());
$session->set('foobar', 'bar'); $session->set('foobar', 'bar');
$session->getFlashes()->set('notice', 'bar'); $session->getFlashBag()->set('notice', 'bar');
$this->request->setSession($session); $this->request->setSession($session);
} }

View File

@ -15,6 +15,7 @@ use Symfony\Component\DependencyInjection\ContainerAware;
use Symfony\Component\HttpFoundation\Response; use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpFoundation\RedirectResponse; use Symfony\Component\HttpFoundation\RedirectResponse;
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException; use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
use Symfony\Component\HttpFoundation\Session\Flash\AutoExpireFlashBag;
/** /**
* ProfilerController. * ProfilerController.
@ -146,9 +147,9 @@ class ProfilerController extends ContainerAware
{ {
$request = $this->container->get('request'); $request = $this->container->get('request');
if (null !== $session = $request->getSession()) { if (null !== $session = $request->getSession() && $session instanceof AutoExpireFlashBag) {
// keep current flashes for one more request // keep current flashes for one more request if using AutoExpireFlashBag
$session->setFlashes($session->getFlashes()); $session->getFlashBag()->setAll($session->getFlashBag()->peekAll());
} }
if (null === $token) { if (null === $token) {

View File

@ -74,9 +74,7 @@ class WebDebugToolbarListener
$session = $request->getSession(); $session = $request->getSession();
if ($session instanceof AutoExpireFlashBag) { if ($session instanceof AutoExpireFlashBag) {
// keep current flashes for one more request if using AutoExpireFlashBag // keep current flashes for one more request if using AutoExpireFlashBag
foreach ($session->getFlashKeys() as $type) { $session->getFlashBag()->setAll($session->getFlashBag()->peekAll());
$session->setFlashes($session->getFlashes($type));
}
} }
$response->setContent($this->templating->render('WebProfilerBundle:Profiler:toolbar_redirect.html.twig', array('location' => $response->headers->get('Location')))); $response->setContent($this->templating->render('WebProfilerBundle:Profiler:toolbar_redirect.html.twig', array('location' => $response->headers->get('Location'))));

View File

@ -241,7 +241,7 @@ class Session implements SessionInterface
* *
* @return FlashBagInterface * @return FlashBagInterface
*/ */
public function getFlashes() public function getFlashBag()
{ {
return $this->getBag('flashes'); return $this->getBag('flashes');
} }