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 * @author Drak <drak@zikula.org>
19 class FlashBag implements FlashBagInterface
21 private $name = 'flashes';
28 private $flashes = array();
31 * The storage key for flashes in the session.
40 * @param string $storageKey The key used to store flashes in the session
42 public function __construct($storageKey = '_sf2_flashes')
44 $this->storageKey = $storageKey;
50 public function getName()
55 public function setName($name)
63 public function initialize(array &$flashes)
65 $this->flashes = &$flashes;
71 public function add($type, $message)
73 $this->flashes[$type][] = $message;
79 public function peek($type, array $default = array())
81 return $this->has($type) ? $this->flashes[$type] : $default;
87 public function peekAll()
89 return $this->flashes;
95 public function get($type, array $default = array())
97 if (!$this->has($type)) {
101 $return = $this->flashes[$type];
103 unset($this->flashes[$type]);
111 public function all()
113 $return = $this->peekAll();
114 $this->flashes = array();
122 public function set($type, $messages)
124 $this->flashes[$type] = (array) $messages;
130 public function setAll(array $messages)
132 $this->flashes = $messages;
138 public function has($type)
140 return array_key_exists($type, $this->flashes) && $this->flashes[$type];
146 public function keys()
148 return array_keys($this->flashes);
154 public function getStorageKey()
156 return $this->storageKey;
162 public function clear()