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 * FlashBag flash message container.
17 * \IteratorAggregate implementation is deprecated and will be removed in 3.0.
19 * @author Drak <drak@zikula.org>
21 class FlashBag implements FlashBagInterface, \IteratorAggregate
23 private $name = 'flashes';
30 private $flashes = array();
33 * The storage key for flashes in the session.
42 * @param string $storageKey The key used to store flashes in the session
44 public function __construct($storageKey = '_sf2_flashes')
46 $this->storageKey = $storageKey;
52 public function getName()
57 public function setName($name)
65 public function initialize(array &$flashes)
67 $this->flashes = &$flashes;
73 public function add($type, $message)
75 $this->flashes[$type][] = $message;
81 public function peek($type, array $default = array())
83 return $this->has($type) ? $this->flashes[$type] : $default;
89 public function peekAll()
91 return $this->flashes;
97 public function get($type, array $default = array())
99 if (!$this->has($type)) {
103 $return = $this->flashes[$type];
105 unset($this->flashes[$type]);
113 public function all()
115 $return = $this->peekAll();
116 $this->flashes = array();
124 public function set($type, $messages)
126 $this->flashes[$type] = (array) $messages;
132 public function setAll(array $messages)
134 $this->flashes = $messages;
140 public function has($type)
142 return array_key_exists($type, $this->flashes) && $this->flashes[$type];
148 public function keys()
150 return array_keys($this->flashes);
156 public function getStorageKey()
158 return $this->storageKey;
164 public function clear()
170 * Returns an iterator for flashes.
172 * @deprecated since version 2.4, to be removed in 3.0.
174 * @return \ArrayIterator An \ArrayIterator instance
176 public function getIterator()
178 @trigger_error('The '.__METHOD__.' method is deprecated since version 2.4 and will be removed in 3.0.', E_USER_DEPRECATED);
180 return new \ArrayIterator($this->all());