1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Ubiquity\utils\http\session; |
4
|
|
|
|
5
|
|
|
/** |
6
|
|
|
* Default php session. |
7
|
|
|
* Ubiquity\utils\http\session$PhpSession |
8
|
|
|
* This class is part of Ubiquity |
9
|
|
|
* |
10
|
|
|
* @author jcheron <[email protected]> |
11
|
|
|
* @version 1.0.0 |
12
|
|
|
* |
13
|
|
|
*/ |
14
|
|
|
class PhpSession extends AbstractSession { |
15
|
|
|
|
16
|
13 |
|
public function set($key, $value) { |
17
|
13 |
|
return $_SESSION [$key] = $value; |
18
|
|
|
} |
19
|
|
|
|
20
|
11 |
|
public function get($key, $default = null) { |
21
|
11 |
|
return $_SESSION [$key] ?? $default; |
22
|
|
|
} |
23
|
|
|
|
24
|
59 |
|
public function start($name = null) { |
25
|
59 |
|
if (! $this->isStarted ()) { |
26
|
36 |
|
if (isset ( $name ) && $name !== '') { |
27
|
|
|
$this->name = $name; |
28
|
|
|
} |
29
|
36 |
|
if (isset ( $this->name )) { |
30
|
|
|
\session_name ( $this->name ); |
31
|
|
|
} |
32
|
36 |
|
\session_start (); |
33
|
|
|
} |
34
|
59 |
|
} |
35
|
|
|
|
36
|
2 |
|
public function terminate() { |
37
|
2 |
|
if (! $this->isStarted ()) |
38
|
|
|
return; |
39
|
2 |
|
$this->start (); |
40
|
2 |
|
$_SESSION = array (); |
41
|
|
|
|
42
|
2 |
|
if (\ini_get ( 'session.use_cookies' )) { |
43
|
2 |
|
$params = \session_get_cookie_params (); |
44
|
2 |
|
\setcookie ( \session_name (), '', \time () - 42000, $params ['path'], $params ['domain'], $params ['secure'], $params ['httponly'] ); |
45
|
|
|
} |
46
|
2 |
|
\session_destroy (); |
47
|
2 |
|
} |
48
|
|
|
|
49
|
59 |
|
public function isStarted() { |
50
|
59 |
|
return \session_status () == PHP_SESSION_ACTIVE; |
51
|
|
|
} |
52
|
|
|
|
53
|
19 |
|
public function exists($key) { |
54
|
19 |
|
return isset ( $_SESSION [$key] ); |
55
|
|
|
} |
56
|
|
|
|
57
|
|
|
public function getAll() { |
58
|
|
|
return $_SESSION; |
59
|
|
|
} |
60
|
|
|
|
61
|
3 |
|
public function delete($key) { |
62
|
3 |
|
unset ( $_SESSION [$key] ); |
63
|
3 |
|
} |
64
|
|
|
} |
65
|
|
|
|
66
|
|
|
|