1 | <?php |
||
11 | class Flash { |
||
12 | /** |
||
13 | * Root storage array or object implementing ArrayAccess |
||
14 | * |
||
15 | * @var array|\ArrayAccess |
||
16 | */ |
||
17 | protected $root_storage = null; |
||
18 | |||
19 | /** |
||
20 | * Child storage array or object implementing ArrayAccess |
||
21 | * |
||
22 | * @var array|\ArrayAccess |
||
23 | */ |
||
24 | protected $storage = null; |
||
25 | |||
26 | /** |
||
27 | * Key to store flashed data in storage with |
||
28 | * |
||
29 | * @var string |
||
30 | */ |
||
31 | protected $storage_key = '__carbonFrameworkFlash'; |
||
32 | |||
33 | /** |
||
34 | * Constructor |
||
35 | * |
||
36 | * @param array|\ArrayAccess $storage |
||
37 | */ |
||
38 | 1 | public function __construct( &$storage ) { |
|
41 | |||
42 | /** |
||
43 | * Return whether a storage object is valid |
||
44 | * |
||
45 | * @param mixed $storage |
||
46 | * @return boolean |
||
47 | */ |
||
48 | 3 | protected function isValidStorage( $storage ) { |
|
49 | 3 | return ( is_array( $storage ) || is_a( $storage, ArrayAccess::class ) ); |
|
50 | } |
||
51 | |||
52 | /** |
||
53 | * Throw an exception if storage is not valid |
||
54 | * |
||
55 | * @throws Exception |
||
56 | * @return null |
||
57 | */ |
||
58 | 1 | protected function validateStorage() { |
|
63 | |||
64 | /** |
||
65 | * Get the storage for flash messages |
||
66 | * |
||
67 | * @return array|\ArrayAccess |
||
68 | */ |
||
69 | 3 | public function getStorage() { |
|
72 | |||
73 | /** |
||
74 | * Set the storage for flash messages |
||
75 | * |
||
76 | * @param array|\ArrayAccess $storage |
||
77 | * @return null |
||
78 | */ |
||
79 | 2 | public function setStorage( &$storage ) { |
|
91 | |||
92 | /** |
||
93 | * Return whether the flash service is enabled |
||
94 | * |
||
95 | * @return boolean |
||
96 | */ |
||
97 | 1 | public function enabled() { |
|
100 | |||
101 | /** |
||
102 | * Get the entire storage or the values for a key |
||
103 | * |
||
104 | * @param string|null $key |
||
105 | * @return array|\ArrayAccess |
||
106 | */ |
||
107 | 8 | public function peek( $key = null ) { |
|
120 | |||
121 | /** |
||
122 | * Get and clear the entire storage or the values for a key |
||
123 | * |
||
124 | * @param string|null $key |
||
125 | * @return array|\ArrayAccess |
||
126 | */ |
||
127 | 1 | public function get( $key = null ) { |
|
134 | |||
135 | /** |
||
136 | * Add values for a key |
||
137 | * |
||
138 | * @param string $key |
||
139 | * @param mixed $new_items |
||
140 | */ |
||
141 | 5 | public function add( $key, $new_items ) { |
|
151 | |||
152 | /** |
||
153 | * Clear the entire storage or the values for a key |
||
154 | * |
||
155 | * @param string|null $key |
||
156 | * @return null |
||
157 | */ |
||
158 | 2 | public function clear( $key = null ) { |
|
169 | } |
||
170 |