1 | <?php |
||
7 | class Session |
||
8 | { |
||
9 | /** |
||
10 | * Age flash data. |
||
11 | * |
||
12 | * @return void |
||
13 | */ |
||
14 | public static function ageFlashData() |
||
20 | |||
21 | /** |
||
22 | * Get all of the items from the session. |
||
23 | * |
||
24 | * @return array |
||
25 | */ |
||
26 | public static function all() |
||
30 | |||
31 | /** |
||
32 | * Remove all of the items from the session. |
||
33 | * |
||
34 | * @return array |
||
35 | */ |
||
36 | public static function clear() |
||
40 | |||
41 | /** |
||
42 | * Flash data for a single request. |
||
43 | * |
||
44 | * @param $key |
||
45 | * @param $value |
||
46 | * |
||
47 | * @return void |
||
48 | */ |
||
49 | public static function flash($key, $value) |
||
57 | |||
58 | /** |
||
59 | * Flash data for a single request. |
||
60 | * |
||
61 | * @param $key |
||
62 | * @param $value |
||
63 | * |
||
64 | * @return void |
||
65 | */ |
||
66 | public static function now($key, $value) |
||
67 | { |
||
68 | static::put($key, $value); |
||
69 | |||
70 | static::push('flash.old', $key); |
||
71 | } |
||
72 | |||
73 | /** |
||
74 | * Remove all of the items from the session. |
||
75 | * |
||
76 | * @return array |
||
77 | */ |
||
78 | public static function flush() |
||
82 | |||
83 | /** |
||
84 | * Remove an item from the session. |
||
85 | * |
||
86 | * @param string $key |
||
87 | * |
||
88 | * @return void |
||
89 | */ |
||
90 | public static function forget($key) |
||
94 | |||
95 | /** |
||
96 | * Get an item from the session. |
||
97 | * |
||
98 | * @param $name |
||
99 | * @param $default |
||
100 | * |
||
101 | * @return mixed |
||
102 | */ |
||
103 | public static function get($name, $default = null) |
||
107 | |||
108 | /** |
||
109 | * Determining if an item exists in the session. |
||
110 | * |
||
111 | * @param $name |
||
112 | * |
||
113 | * @return bool |
||
114 | */ |
||
115 | public static function has($name) |
||
119 | |||
120 | /** |
||
121 | * Reflash a subset of the current flash data. |
||
122 | * |
||
123 | * @param $keys |
||
124 | * |
||
125 | * @return void |
||
126 | */ |
||
127 | public static function keep($keys = null) |
||
134 | |||
135 | /** |
||
136 | * Get the value of a given key and then forget it. |
||
137 | * |
||
138 | * @param $key |
||
139 | * @param $default |
||
140 | * |
||
141 | * @return mixed |
||
142 | */ |
||
143 | public static function pull($key, $default = null) |
||
147 | |||
148 | /** |
||
149 | * Push a value onto a session array. |
||
150 | * |
||
151 | * @param $key |
||
152 | * @param $value |
||
153 | * |
||
154 | * @return void |
||
155 | */ |
||
156 | public static function push($key, $value) |
||
163 | |||
164 | /** |
||
165 | * Put a key / value pair in the session. |
||
166 | * |
||
167 | * @param $key |
||
168 | * @param $value |
||
169 | * |
||
170 | * @return void |
||
171 | */ |
||
172 | public static function put($key, $value = null) |
||
182 | |||
183 | /** |
||
184 | * Set an item in the session. |
||
185 | * |
||
186 | * @param $name |
||
187 | * @param $value |
||
188 | * |
||
189 | * @return void |
||
190 | */ |
||
191 | public static function set($name, $value) |
||
195 | |||
196 | /** |
||
197 | * Reflash all flash data for one more request. |
||
198 | */ |
||
199 | public static function reflash() |
||
205 | |||
206 | /** |
||
207 | * Remove all old flash data from the session. |
||
208 | * |
||
209 | * @return void |
||
210 | */ |
||
211 | public static function removeOldFlashData() |
||
219 | |||
220 | /** |
||
221 | * Merge new flash keys into the new flash array. |
||
222 | * |
||
223 | * @param array $keys |
||
224 | * |
||
225 | * @return void |
||
226 | */ |
||
227 | protected static function mergeWithCurrentFlashes(array $keys) |
||
233 | |||
234 | /** |
||
235 | * Remove the given keys from the old flash data. |
||
236 | * |
||
237 | * @param array $keys |
||
238 | * |
||
239 | * @return void |
||
240 | */ |
||
241 | protected static function removeFromOldFlashData(array $keys) |
||
247 | } |
||
248 |
Instead of super-globals, we recommend to explicitly inject the dependencies of your class. This makes your code less dependent on global state and it becomes generally more testable: