1 | <?php |
||
17 | class FlashBag implements FlashBagInterface |
||
18 | { |
||
19 | /** |
||
20 | * @var string |
||
21 | */ |
||
22 | private $name = 'flashes'; |
||
23 | |||
24 | /** |
||
25 | * @var string |
||
26 | */ |
||
27 | private $storageKey; |
||
28 | |||
29 | /** |
||
30 | * @var array |
||
31 | */ |
||
32 | private $flashes = array(); |
||
33 | |||
34 | /** |
||
35 | * @var array |
||
36 | */ |
||
37 | private $keeps = array(); |
||
38 | |||
39 | /** |
||
40 | * Constructor. |
||
41 | * |
||
42 | * @param string $storageKey |
||
43 | */ |
||
44 | public function __construct($storageKey = '___BOROBUDUR_FLASHES') |
||
48 | |||
49 | /** |
||
50 | * Clear keep keys and replace with sets of it. |
||
51 | * |
||
52 | * @param array $keys |
||
53 | * |
||
54 | * @return $this |
||
55 | */ |
||
56 | public function replaceKeep(array $keys) |
||
62 | |||
63 | /** |
||
64 | * Add sets of keep keys. |
||
65 | * |
||
66 | * @param array $keys |
||
67 | * |
||
68 | * @return $this |
||
69 | */ |
||
70 | public function addKeep(array $keys) |
||
78 | |||
79 | /** |
||
80 | * Set keep key. |
||
81 | * |
||
82 | * Keep data with specified key. |
||
83 | * |
||
84 | * @param string $key |
||
85 | * |
||
86 | * @return $this |
||
87 | */ |
||
88 | public function setKeep($key) |
||
94 | |||
95 | /** |
||
96 | * Check if specified key is kept. |
||
97 | * |
||
98 | * @param string $key |
||
99 | * |
||
100 | * @return bool |
||
101 | */ |
||
102 | public function isKept($key) |
||
106 | |||
107 | /** |
||
108 | * Remove keep key. |
||
109 | * |
||
110 | * @param string $key |
||
111 | * |
||
112 | * @return $this |
||
113 | */ |
||
114 | public function removeKeep($key) |
||
122 | |||
123 | /** |
||
124 | * Clear all flash data and replace with sets of it. |
||
125 | * |
||
126 | * @param array $values |
||
127 | * |
||
128 | * @return $this |
||
129 | */ |
||
130 | public function replace(array $values) |
||
136 | |||
137 | /** |
||
138 | * Add sets of flash data. |
||
139 | * |
||
140 | * @param array $values |
||
141 | * |
||
142 | * @return $this |
||
143 | */ |
||
144 | public function add(array $values) |
||
152 | |||
153 | /** |
||
154 | * Set flash data. |
||
155 | * |
||
156 | * @param string $key |
||
157 | * @param mixed $value |
||
158 | * |
||
159 | * @return $this |
||
160 | */ |
||
161 | public function set($key, $value) |
||
167 | |||
168 | /** |
||
169 | * Get flash data by key. |
||
170 | * |
||
171 | * @param string $key |
||
172 | * @param mixed|null $default |
||
173 | * |
||
174 | * @return mixed |
||
175 | */ |
||
176 | public function peek($key, $default = null) |
||
184 | |||
185 | /** |
||
186 | * Get all flash data. |
||
187 | * |
||
188 | * @return array |
||
189 | */ |
||
190 | public function peekAll() |
||
194 | |||
195 | /** |
||
196 | * Get flash data by key and clear it. |
||
197 | * |
||
198 | * @param string $key |
||
199 | * @param mixed|null $default |
||
200 | * |
||
201 | * @return mixed |
||
202 | */ |
||
203 | public function get($key, $default = null) |
||
214 | |||
215 | /** |
||
216 | * Check if flash data exist or not by key. |
||
217 | * |
||
218 | * @param string $key |
||
219 | * |
||
220 | * @return bool |
||
221 | */ |
||
222 | public function has($key) |
||
226 | |||
227 | /** |
||
228 | * Get all flash data and clear it. |
||
229 | * |
||
230 | * @return array |
||
231 | */ |
||
232 | public function all() |
||
243 | |||
244 | /** |
||
245 | * Get all flash data keys. |
||
246 | * |
||
247 | * @return array |
||
248 | */ |
||
249 | public function keys() |
||
253 | |||
254 | /** |
||
255 | * {@inheritdoc} |
||
256 | */ |
||
257 | public function count() |
||
261 | |||
262 | /** |
||
263 | * Get session bag name. |
||
264 | * |
||
265 | * @return string |
||
266 | */ |
||
267 | public function getName() |
||
271 | |||
272 | /** |
||
273 | * Identity storage. |
||
274 | * |
||
275 | * @return string |
||
276 | */ |
||
277 | public function getStorageKey() |
||
281 | |||
282 | /** |
||
283 | * Initialize sessions. |
||
284 | * |
||
285 | * @param array $sessions |
||
286 | */ |
||
287 | public function initialize(array &$sessions) |
||
300 | |||
301 | /** |
||
302 | * Flush un-keep flash. |
||
303 | * |
||
304 | * @param string $key |
||
305 | */ |
||
306 | private function flush($key) |
||
316 | |||
317 | /** |
||
318 | * Clear session and return all data. |
||
319 | * |
||
320 | * @return array |
||
321 | */ |
||
322 | public function clear() |
||
326 | } |
||
327 |