1 | <?php |
||
22 | class Configuration |
||
23 | { |
||
24 | use NativeSessionTrait; |
||
25 | |||
26 | const SESSION_ID_LENGTH = 80; |
||
27 | const SESSION_NAME_DEFAULT = 'PHPSESSID'; |
||
28 | const TIMEOUT_KEY_DEFAULT = '__SESSIONWARE_TIMEOUT__'; |
||
29 | |||
30 | const SAME_SITE_LAX = 'Lax'; |
||
31 | const SAME_SITE_STRICT = 'Strict'; |
||
32 | |||
33 | const LIFETIME_FLASH = 300; // 5 minutes |
||
34 | const LIFETIME_SHORT = 600; // 10 minutes |
||
35 | const LIFETIME_NORMAL = 900; // 15 minutes |
||
36 | const LIFETIME_DEFAULT = 1440; // 24 minutes |
||
37 | const LIFETIME_EXTENDED = 3600; // 1 hour |
||
38 | |||
39 | const LIFETIME_INFINITE = PHP_INT_MAX; // Around 1145 years (x86_64) |
||
40 | |||
41 | /** |
||
42 | * @var string |
||
43 | */ |
||
44 | protected $name; |
||
45 | |||
46 | /** |
||
47 | * @var string |
||
48 | */ |
||
49 | protected $savePath; |
||
50 | |||
51 | /** |
||
52 | * @var int |
||
53 | */ |
||
54 | protected $lifetime; |
||
55 | |||
56 | /** |
||
57 | * @var string |
||
58 | */ |
||
59 | protected $cookiePath; |
||
60 | |||
61 | /** |
||
62 | * @var string |
||
63 | */ |
||
64 | protected $cookieDomain; |
||
65 | |||
66 | /** |
||
67 | * @var bool |
||
68 | */ |
||
69 | protected $cookieSecure; |
||
70 | |||
71 | /** |
||
72 | * @var bool |
||
73 | */ |
||
74 | protected $cookieHttpOnly; |
||
75 | |||
76 | /** |
||
77 | * @var string |
||
78 | */ |
||
79 | protected $cookieSameSite; |
||
80 | |||
81 | /** |
||
82 | * @var Key |
||
83 | */ |
||
84 | protected $encryptionKey; |
||
85 | |||
86 | /** |
||
87 | * @var string |
||
88 | */ |
||
89 | protected $timeoutKey; |
||
90 | |||
91 | /** |
||
92 | * Configuration constructor. |
||
93 | * |
||
94 | * @param array $configurations |
||
95 | */ |
||
96 | public function __construct(array $configurations = []) |
||
105 | |||
106 | /** |
||
107 | * Retrieve default session settings. |
||
108 | * |
||
109 | * @return array |
||
110 | */ |
||
111 | protected function getDefaultSessionSettings() : array |
||
130 | |||
131 | /** |
||
132 | * Seed configurations. |
||
133 | * |
||
134 | * @param array $configurations |
||
135 | */ |
||
136 | protected function seedConfigurations(array $configurations) |
||
159 | |||
160 | /** |
||
161 | * Get session name. |
||
162 | * |
||
163 | * @return string |
||
164 | */ |
||
165 | public function getName() : string |
||
169 | |||
170 | /** |
||
171 | * Set session name. |
||
172 | * |
||
173 | * @param string $name |
||
174 | * |
||
175 | * @throws \InvalidArgumentException |
||
176 | * |
||
177 | * @return self |
||
178 | */ |
||
179 | public function setName(string $name) |
||
189 | |||
190 | /** |
||
191 | * Get session cookie path. |
||
192 | * |
||
193 | * @return string |
||
194 | */ |
||
195 | public function getCookiePath() : string |
||
199 | |||
200 | /** |
||
201 | * Set session cookie path. |
||
202 | * |
||
203 | * @param string $cookiePath |
||
204 | * |
||
205 | * @return self |
||
206 | */ |
||
207 | public function setCookiePath(string $cookiePath) |
||
213 | |||
214 | /** |
||
215 | * Get session cookie domain. |
||
216 | * |
||
217 | * @return string |
||
218 | */ |
||
219 | public function getCookieDomain() : string |
||
223 | |||
224 | /** |
||
225 | * Set session cookie domain. |
||
226 | * |
||
227 | * @param string $cookieDomain |
||
228 | * |
||
229 | * @return self |
||
230 | */ |
||
231 | public function setCookieDomain(string $cookieDomain) |
||
237 | |||
238 | /** |
||
239 | * Is session cookie HTTPS only. |
||
240 | * |
||
241 | * @return bool |
||
242 | */ |
||
243 | public function isCookieSecure() : bool |
||
247 | |||
248 | /** |
||
249 | * Set session cookie HTTPS only. |
||
250 | * |
||
251 | * @param bool $cookieSecure |
||
252 | * |
||
253 | * @return self |
||
254 | */ |
||
255 | public function setCookieSecure(bool $cookieSecure) |
||
261 | |||
262 | /** |
||
263 | * Is session cookie HTTP only. |
||
264 | * |
||
265 | * @return bool |
||
266 | */ |
||
267 | public function isCookieHttpOnly() : bool |
||
271 | |||
272 | /** |
||
273 | * Set session cookie HTTP only. |
||
274 | * |
||
275 | * @param bool $cookieHttpOnly |
||
276 | * |
||
277 | * @return self |
||
278 | */ |
||
279 | public function setCookieHttpOnly(bool $cookieHttpOnly) |
||
285 | |||
286 | /** |
||
287 | * Get cookie SameSite restriction. |
||
288 | * |
||
289 | * @return string |
||
290 | */ |
||
291 | public function getCookieSameSite(): string |
||
295 | |||
296 | /** |
||
297 | * Set cookie SameSite restriction. |
||
298 | * |
||
299 | * @param string $cookieSameSite |
||
300 | * |
||
301 | * @throws \InvalidArgumentException |
||
302 | */ |
||
303 | public function setCookieSameSite(string $cookieSameSite) |
||
313 | |||
314 | /** |
||
315 | * Get session save path. |
||
316 | * |
||
317 | * @return string |
||
318 | */ |
||
319 | public function getSavePath() : string |
||
323 | |||
324 | /** |
||
325 | * Set session save path. |
||
326 | * |
||
327 | * @param string $savePath |
||
328 | * |
||
329 | * @throws \InvalidArgumentException |
||
330 | * |
||
331 | * @return self |
||
332 | */ |
||
333 | public function setSavePath(string $savePath) |
||
343 | |||
344 | /** |
||
345 | * Get session lifetime. |
||
346 | * |
||
347 | * @return int |
||
348 | */ |
||
349 | public function getLifetime() : int |
||
353 | |||
354 | /** |
||
355 | * Set session lifetime. |
||
356 | * |
||
357 | * @param int $lifetime |
||
358 | * |
||
359 | * @throws \InvalidArgumentException |
||
360 | * |
||
361 | * @return self |
||
362 | */ |
||
363 | public function setLifetime(int $lifetime) |
||
373 | |||
374 | /** |
||
375 | * Set session encryption key. |
||
376 | * |
||
377 | * @return Key|null |
||
378 | */ |
||
379 | public function getEncryptionKey() |
||
383 | |||
384 | /** |
||
385 | * Set session encryption key. |
||
386 | * |
||
387 | * @param Key $encryptionKey |
||
388 | * |
||
389 | * @return self |
||
390 | */ |
||
391 | public function setEncryptionKey(Key $encryptionKey) : self |
||
397 | |||
398 | /** |
||
399 | * Get session timeout control key. |
||
400 | * |
||
401 | * @return string |
||
402 | */ |
||
403 | public function getTimeoutKey() : string |
||
407 | |||
408 | /** |
||
409 | * Set session timeout control key. |
||
410 | * |
||
411 | * @param string $timeoutKey |
||
412 | * |
||
413 | * @throws \InvalidArgumentException |
||
414 | * |
||
415 | * @return self |
||
416 | */ |
||
417 | public function setTimeoutKey(string $timeoutKey) : self |
||
427 | } |
||
428 |