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';
22 private $flashes = array();
26 * @param string $storageKey The key used to store flashes in the session
28 public function __construct($storageKey = '_symfony_flashes')
30 $this->storageKey = $storageKey;
36 public function getName()
41 public function setName($name)
49 public function initialize(array &$flashes)
51 $this->flashes = &$flashes;
57 public function add($type, $message)
59 $this->flashes[$type][] = $message;
65 public function peek($type, array $default = array())
67 return $this->has($type) ? $this->flashes[$type] : $default;
73 public function peekAll()
75 return $this->flashes;
81 public function get($type, array $default = array())
83 if (!$this->has($type)) {
87 $return = $this->flashes[$type];
89 unset($this->flashes[$type]);
99 $return = $this->peekAll();
100 $this->flashes = array();
108 public function set($type, $messages)
110 $this->flashes[$type] = (array) $messages;
116 public function setAll(array $messages)
118 $this->flashes = $messages;
124 public function has($type)
126 return array_key_exists($type, $this->flashes) && $this->flashes[$type];
132 public function keys()
134 return array_keys($this->flashes);
140 public function getStorageKey()
142 return $this->storageKey;
148 public function clear()