1 | <?php |
||
32 | class ServletSessionWrapper |
||
33 | { |
||
34 | |||
35 | /** |
||
36 | * The session instance. |
||
37 | * |
||
38 | * @var \AppserverIo\Psr\Servlet\ServletSessionInterface |
||
39 | */ |
||
40 | protected $session; |
||
41 | |||
42 | /** |
||
43 | * Injects the passed session instance into this servlet session wrapper. |
||
44 | * |
||
45 | * @param \AppserverIo\Psr\Servlet\ServletSessionInterface $session The session instance used for initialization |
||
46 | * |
||
47 | * @return void |
||
48 | */ |
||
49 | public function injectSession(ServletSessionInterface $session) |
||
53 | |||
54 | /** |
||
55 | * Returns the servlet session instance. |
||
56 | * |
||
57 | * @return \AppserverIo\Psr\Servlet\ServletSessionInterface The session instance |
||
58 | */ |
||
59 | public function getSession() |
||
63 | |||
64 | /** |
||
65 | * Starts the session, if it has not been already started |
||
66 | * |
||
67 | * @return void |
||
68 | */ |
||
69 | public function start() |
||
73 | |||
74 | /** |
||
75 | * Tells if the session has been started already. |
||
76 | * |
||
77 | * @return boolean |
||
78 | */ |
||
79 | public function isStarted() |
||
83 | |||
84 | /** |
||
85 | * Returns the current session identifier |
||
86 | * |
||
87 | * @return string The current session identifier |
||
88 | */ |
||
89 | public function getId() |
||
93 | |||
94 | /** |
||
95 | * Sets the current session identifier. |
||
96 | * |
||
97 | * @param string $id The current session identifier |
||
98 | * |
||
99 | * @return void |
||
100 | */ |
||
101 | public function setId($id) |
||
105 | |||
106 | /** |
||
107 | * Returns the unix time stamp marking the last point in time this session has |
||
108 | * been in use. |
||
109 | * |
||
110 | * For the current (local) session, this method will always return the current |
||
111 | * time. For a remote session, the unix timestamp will be returned. |
||
112 | * |
||
113 | * @return integer UNIX timestamp |
||
114 | */ |
||
115 | public function getLastActivityTimestamp() |
||
119 | |||
120 | /** |
||
121 | * Returns the session name. |
||
122 | * |
||
123 | * @return string The session name |
||
124 | */ |
||
125 | public function getName() |
||
129 | |||
130 | /** |
||
131 | * Sets the session name. |
||
132 | * |
||
133 | * @param string $name The session name |
||
134 | * |
||
135 | * @return void |
||
136 | */ |
||
137 | public function setName($name) |
||
141 | |||
142 | /** |
||
143 | * Returns date and time after the session expires. |
||
144 | * |
||
145 | * @return integer|\DateTime The date and time after the session expires |
||
146 | */ |
||
147 | public function getLifetime() |
||
151 | |||
152 | /** |
||
153 | * Sets date and time after the session expires. |
||
154 | * |
||
155 | * @param integer|\DateTime $lifetime The date and time after the session expires |
||
156 | * |
||
157 | * @return void |
||
158 | */ |
||
159 | public function setLifetime($lifetime) |
||
163 | |||
164 | /** |
||
165 | * Returns the number of seconds until the session expires. |
||
166 | * |
||
167 | * @return integer|null Number of seconds until the session expires |
||
168 | */ |
||
169 | public function getMaximumAge() |
||
173 | |||
174 | /** |
||
175 | * Sets the number of seconds until the session expires. |
||
176 | * |
||
177 | * @param integer $maximumAge Number of seconds until the session expires |
||
178 | * |
||
179 | * @return void |
||
180 | */ |
||
181 | public function setMaximumAge($maximumAge) |
||
185 | |||
186 | /** |
||
187 | * Returns the host to which the user agent will send this cookie. |
||
188 | * |
||
189 | * @return string|null The host to which the user agent will send this cookie |
||
190 | */ |
||
191 | public function getDomain() |
||
195 | |||
196 | /** |
||
197 | * Sets the host to which the user agent will send this cookie. |
||
198 | * |
||
199 | * @param string $domain The host to which the user agent will send this cookie |
||
200 | * |
||
201 | * @return void |
||
202 | */ |
||
203 | public function setDomain($domain) |
||
207 | |||
208 | /** |
||
209 | * Returns the path describing the scope of this cookie. |
||
210 | * |
||
211 | * @return string The path describing the scope of this cookie |
||
212 | */ |
||
213 | public function getPath() |
||
217 | |||
218 | /** |
||
219 | * Sets the path describing the scope of this cookie. |
||
220 | * |
||
221 | * @param string $path The path describing the scope of this cookie |
||
222 | * |
||
223 | * @return void |
||
224 | */ |
||
225 | public function setPath($path) |
||
229 | |||
230 | /** |
||
231 | * Returns if this session should only be sent through a "secure" channel by the user agent. |
||
232 | * |
||
233 | * @return boolean TRUE if the session should only be sent through a "secure" channel, else FALSE |
||
234 | */ |
||
235 | public function isSecure() |
||
239 | |||
240 | /** |
||
241 | * Sets the flag that this session should only be sent through a "secure" channel by the user agent. |
||
242 | * |
||
243 | * @param boolean $secure TRUE if the session should only be sent through a "secure" channel, else FALSE |
||
244 | * |
||
245 | * @return void |
||
246 | */ |
||
247 | public function setSecure($secure = true) |
||
251 | |||
252 | /** |
||
253 | * Returns if this session should only be used through the HTTP protocol. |
||
254 | * |
||
255 | * @return boolean TRUE if the session should only be used through the HTTP protocol |
||
256 | */ |
||
257 | public function isHttpOnly() |
||
261 | |||
262 | /** |
||
263 | * Sets the flag that this session should only be used through the HTTP protocol. |
||
264 | * |
||
265 | * @param boolean $httpOnly TRUE if the session should only be used through the HTTP protocol |
||
266 | * |
||
267 | * @return void |
||
268 | */ |
||
269 | public function setHttpOnly($httpOnly = true) |
||
273 | |||
274 | /** |
||
275 | * Returns the data associated with the given key. |
||
276 | * |
||
277 | * @param string $key An identifier for the content stored in the session. |
||
278 | * |
||
279 | * @return mixed The contents associated with the given key |
||
280 | */ |
||
281 | public function getData($key) |
||
285 | |||
286 | /** |
||
287 | * Returns TRUE if a session data entry $key is available. |
||
288 | * |
||
289 | * @param string $key Entry identifier of the session data |
||
290 | * |
||
291 | * @return boolean |
||
292 | */ |
||
293 | public function hasKey($key) |
||
297 | |||
298 | /** |
||
299 | * Stores the given data under the given key in the session |
||
300 | * |
||
301 | * @param string $key The key under which the data should be stored |
||
302 | * @param mixed $data The data to be stored |
||
303 | * |
||
304 | * @return void |
||
305 | */ |
||
306 | public function putData($key, $data) |
||
310 | |||
311 | /** |
||
312 | * Tags this session with the given tag. |
||
313 | * |
||
314 | * Note that third-party libraries might also tag your session. Therefore it is |
||
315 | * recommended to use namespaced tags such as "Acme-Demo-MySpecialTag". |
||
316 | * |
||
317 | * @param string $tag The tag – must match be a valid cache frontend tag |
||
318 | * |
||
319 | * @return void |
||
320 | */ |
||
321 | public function addTag($tag) |
||
325 | |||
326 | /** |
||
327 | * Removes the specified tag from this session. |
||
328 | * |
||
329 | * @param string $tag The tag – must match be a valid cache frontend tag |
||
330 | * |
||
331 | * @return void |
||
332 | */ |
||
333 | public function removeTag($tag) |
||
337 | |||
338 | /** |
||
339 | * Returns the tags this session has been tagged with. |
||
340 | * |
||
341 | * @return array The tags or an empty array if there aren't any |
||
342 | */ |
||
343 | public function getTags() |
||
347 | |||
348 | /** |
||
349 | * Returns TRUE if there is a session that can be resumed. |
||
350 | * |
||
351 | * If a to-be-resumed session was inactive for too long, this function will |
||
352 | * trigger the expiration of that session. An expired session cannot be resumed. |
||
353 | * |
||
354 | * NOTE that this method does a bit more than the name implies: Because the |
||
355 | * session info data needs to be loaded, this method stores this data already |
||
356 | * so it doesn't have to be loaded again once the session is being used. |
||
357 | * |
||
358 | * @return boolean |
||
359 | */ |
||
360 | public function canBeResumed() |
||
364 | |||
365 | /** |
||
366 | * Resumes an existing session, if any. |
||
367 | * |
||
368 | * @return integer If a session was resumed, the inactivity of since the last request is returned |
||
369 | */ |
||
370 | public function resume() |
||
374 | |||
375 | /** |
||
376 | * Explicitly destroys all session data. |
||
377 | * |
||
378 | * @param string $reason The reason why the session has been destroyed |
||
379 | * |
||
380 | * @return void |
||
381 | */ |
||
382 | public function destroy($reason) |
||
386 | |||
387 | /** |
||
388 | * Returns the checksum for this session instance. |
||
389 | * |
||
390 | * @return string The checksum |
||
391 | */ |
||
392 | public function checksum() |
||
396 | } |
||
397 |