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';
28 private $flashes = array('display' => array(), 'new' => 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;
67 // The logic: messages from the last request will be stored in new, so we move them to previous
68 // This request we will show what is in 'display'. What is placed into 'new' this time round will
69 // be moved to display next time round.
70 $this->flashes['display'] = array_key_exists('new', $this->flashes) ? $this->flashes['new'] : array();
71 $this->flashes['new'] = array();
77 public function add($type, $message)
79 $this->flashes['new'][$type][] = $message;
85 public function peek($type, array $default = array())
87 return $this->has($type) ? $this->flashes['display'][$type] : $default;
93 public function peekAll()
95 return array_key_exists('display', $this->flashes) ? (array) $this->flashes['display'] : array();
101 public function get($type, array $default = array())
105 if (!$this->has($type)) {
109 if (isset($this->flashes['display'][$type])) {
110 $return = $this->flashes['display'][$type];
111 unset($this->flashes['display'][$type]);
120 public function all()
122 $return = $this->flashes['display'];
123 $this->flashes = array('new' => array(), 'display' => array());
131 public function setAll(array $messages)
133 $this->flashes['new'] = $messages;
139 public function set($type, $messages)
141 $this->flashes['new'][$type] = (array) $messages;
147 public function has($type)
149 return array_key_exists($type, $this->flashes['display']) && $this->flashes['display'][$type];
155 public function keys()
157 return array_keys($this->flashes['display']);
163 public function getStorageKey()
165 return $this->storageKey;
171 public function clear()