composer package updates
[openemr.git] / vendor / symfony / http-foundation / Session / Flash / AutoExpireFlashBag.php
blob0ed66009743713be5572e6ae8c05c2cb1b307d40
1 <?php
3 /*
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;
14 /**
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());
23 private $storageKey;
25 /**
26 * @param string $storageKey The key used to store flashes in the session
28 public function __construct($storageKey = '_sf2_flashes')
30 $this->storageKey = $storageKey;
33 /**
34 * {@inheritdoc}
36 public function getName()
38 return $this->name;
41 public function setName($name)
43 $this->name = $name;
46 /**
47 * {@inheritdoc}
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();
60 /**
61 * {@inheritdoc}
63 public function add($type, $message)
65 $this->flashes['new'][$type][] = $message;
68 /**
69 * {@inheritdoc}
71 public function peek($type, array $default = array())
73 return $this->has($type) ? $this->flashes['display'][$type] : $default;
76 /**
77 * {@inheritdoc}
79 public function peekAll()
81 return array_key_exists('display', $this->flashes) ? (array) $this->flashes['display'] : array();
84 /**
85 * {@inheritdoc}
87 public function get($type, array $default = array())
89 $return = $default;
91 if (!$this->has($type)) {
92 return $return;
95 if (isset($this->flashes['display'][$type])) {
96 $return = $this->flashes['display'][$type];
97 unset($this->flashes['display'][$type]);
100 return $return;
104 * {@inheritdoc}
106 public function all()
108 $return = $this->flashes['display'];
109 $this->flashes['display'] = array();
111 return $return;
115 * {@inheritdoc}
117 public function setAll(array $messages)
119 $this->flashes['new'] = $messages;
123 * {@inheritdoc}
125 public function set($type, $messages)
127 $this->flashes['new'][$type] = (array) $messages;
131 * {@inheritdoc}
133 public function has($type)
135 return array_key_exists($type, $this->flashes['display']) && $this->flashes['display'][$type];
139 * {@inheritdoc}
141 public function keys()
143 return array_keys($this->flashes['display']);
147 * {@inheritdoc}
149 public function getStorageKey()
151 return $this->storageKey;
155 * {@inheritdoc}
157 public function clear()
159 return $this->all();