4 * This file is part of the Symfony package.
6 * (c) Fabien Potencier <fabien@symfony.com>
8 * For the full copyright and license information, please view the LICENSE
9 * file that was distributed with this source code.
12 namespace Symfony\Component\HttpFoundation\Session\Flash
;
15 * AutoExpireFlashBag flash message container.
17 * @author Drak <drak@zikula.org>
19 class AutoExpireFlashBag
implements FlashBagInterface
21 private $name = 'flashes';
22 private $flashes = array('display' => array(), 'new' => array());
26 * @param string $storageKey The key used to store flashes in the session
28 public function __construct($storageKey = '_sf2_flashes')
30 $this->storageKey
= $storageKey;
36 public function getName()
41 public function setName($name)
49 public function initialize(array &$flashes)
51 $this->flashes
= &$flashes;
53 // The logic: messages from the last request will be stored in new, so we move them to previous
54 // This request we will show what is in 'display'. What is placed into 'new' this time round will
55 // be moved to display next time round.
56 $this->flashes
['display'] = array_key_exists('new', $this->flashes
) ?
$this->flashes
['new'] : array();
57 $this->flashes
['new'] = array();
63 public function add($type, $message)
65 $this->flashes
['new'][$type][] = $message;
71 public function peek($type, array $default = array())
73 return $this->has($type) ?
$this->flashes
['display'][$type] : $default;
79 public function peekAll()
81 return array_key_exists('display', $this->flashes
) ?
(array) $this->flashes
['display'] : array();
87 public function get($type, array $default = array())
91 if (!$this->has($type)) {
95 if (isset($this->flashes
['display'][$type])) {
96 $return = $this->flashes
['display'][$type];
97 unset($this->flashes
['display'][$type]);
106 public function all()
108 $return = $this->flashes
['display'];
109 $this->flashes
['display'] = array();
117 public function setAll(array $messages)
119 $this->flashes
['new'] = $messages;
125 public function set($type, $messages)
127 $this->flashes
['new'][$type] = (array) $messages;
133 public function has($type)
135 return array_key_exists($type, $this->flashes
['display']) && $this->flashes
['display'][$type];
141 public function keys()
143 return array_keys($this->flashes
['display']);
149 public function getStorageKey()
151 return $this->storageKey
;
157 public function clear()