1 | <?php |
||
9 | class Session implements SessionInterface |
||
10 | { |
||
11 | /** |
||
12 | * Session prefix name |
||
13 | * @var string |
||
14 | */ |
||
15 | private $_prefix; |
||
16 | |||
17 | /** |
||
18 | * Session constructor. |
||
19 | * |
||
20 | * @param string|null $prefix |
||
21 | */ |
||
22 | public function __construct(string $prefix = null) |
||
26 | |||
27 | /** |
||
28 | * @return string|null |
||
29 | */ |
||
30 | public function getPrefix() |
||
34 | |||
35 | /** |
||
36 | * @param string|null $prefix |
||
37 | * @return SessionInterface |
||
38 | */ |
||
39 | public function setPrefix(string $prefix = null): SessionInterface |
||
44 | |||
45 | /** |
||
46 | * @return bool |
||
47 | */ |
||
48 | public function isStarted(): bool |
||
52 | |||
53 | /** |
||
54 | * if session has not started, start sessions |
||
55 | * |
||
56 | * @return string |
||
57 | */ |
||
58 | public function init(): string |
||
65 | |||
66 | /** |
||
67 | * Add value to a session. |
||
68 | * |
||
69 | * @param array|string $name name the data to save |
||
70 | * @param string|bool $value the data to save |
||
71 | * @return SessionInterface |
||
72 | */ |
||
73 | public function set($name, $value = false): SessionInterface |
||
85 | |||
86 | /** |
||
87 | * Extract item from session then delete from the session, |
||
88 | * finally return the item. |
||
89 | * |
||
90 | * @param string $name item to extract |
||
91 | * @return mixed |
||
92 | */ |
||
93 | public function pull(string $name): string |
||
105 | |||
106 | /** |
||
107 | * Get item from session |
||
108 | * |
||
109 | * @param string $name item to look for in session |
||
110 | * @return mixed |
||
111 | */ |
||
112 | public function get(string $name) |
||
117 | |||
118 | /** |
||
119 | * Return session id |
||
120 | * |
||
121 | * @return string with the session id. |
||
122 | */ |
||
123 | public function id(): string |
||
127 | |||
128 | /** |
||
129 | * Regenerate session_id and return new id |
||
130 | * |
||
131 | * @return string |
||
132 | */ |
||
133 | public function regenerate(): string |
||
138 | |||
139 | /** |
||
140 | * Return the session array. |
||
141 | * |
||
142 | * @return array of session indexes |
||
143 | */ |
||
144 | public function display(): array |
||
148 | |||
149 | /** |
||
150 | * Clean all keys stored in session array |
||
151 | * |
||
152 | * @param string|null $prefix |
||
153 | * @return SessionInterface |
||
154 | */ |
||
155 | private function cleanUp(string $prefix = null): SessionInterface |
||
170 | |||
171 | /** |
||
172 | * Remove some single key, remove keys by prefix or destroy session |
||
173 | * |
||
174 | * @param string $name session name to destroy |
||
175 | * @param boolean $byPrefix if set to true clear all sessions for current prefix of session |
||
176 | * @return SessionInterface |
||
177 | */ |
||
178 | public function destroy($name = '', $byPrefix = false): SessionInterface |
||
192 | |||
193 | } |
||
194 |