1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* THttpSessionHandler class |
5
|
|
|
* |
6
|
|
|
* @author Fabio Bas <[email protected]> |
7
|
|
|
* @link https://github.com/pradosoft/prado |
8
|
|
|
* @license https://github.com/pradosoft/prado/blob/master/LICENSE |
9
|
|
|
*/ |
10
|
|
|
|
11
|
|
|
namespace Prado\Web; |
12
|
|
|
|
13
|
|
|
use Prado\Exceptions\TInvalidDataTypeException; |
14
|
|
|
|
15
|
|
|
/** |
16
|
|
|
* THttpSessionHandler class |
17
|
|
|
* |
18
|
|
|
* THttpSessionHandler contains methods called internally by PHP when using |
19
|
|
|
* {@see THttpSession::setUseCustomStorage THttpSession::UseCustomStorage} |
20
|
|
|
* |
21
|
|
|
* @author Fabio Bas <[email protected]> |
22
|
|
|
* @since 4.3.1 |
23
|
|
|
*/ |
24
|
|
|
class THttpSessionHandler implements \SessionHandlerInterface |
25
|
|
|
{ |
26
|
|
|
/** |
27
|
|
|
* @var THttpSession |
28
|
|
|
*/ |
29
|
|
|
private $_session; |
30
|
|
|
|
31
|
|
|
/** |
32
|
|
|
* Constructor. |
33
|
|
|
* @param object $session |
34
|
|
|
* @throws TInvalidDataTypeException if the object is not a THttpSession |
35
|
|
|
*/ |
36
|
|
|
public function __construct($session) |
37
|
|
|
{ |
38
|
|
|
if (!($session instanceof THttpSession)) { |
39
|
|
|
throw new TInvalidDataTypeException(500, 'httpsession_handler_invalid'); |
40
|
|
|
} |
41
|
|
|
|
42
|
|
|
$this->_session = $session; |
43
|
|
|
} |
44
|
|
|
|
45
|
|
|
/** |
46
|
|
|
* Session close handler. |
47
|
|
|
* @return bool whether session is closed successfully |
48
|
|
|
*/ |
49
|
|
|
public function close(): bool |
50
|
|
|
{ |
51
|
|
|
return $this->_session->_close(); |
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
/** |
55
|
|
|
* Session destroy handler. |
56
|
|
|
* @param string $id session ID |
57
|
|
|
* @return bool whether session is destroyed successfully |
58
|
|
|
*/ |
59
|
|
|
public function destroy(string $id): bool |
60
|
|
|
{ |
61
|
|
|
return $this->_session->_destroy($id); |
62
|
|
|
} |
63
|
|
|
|
64
|
|
|
/** |
65
|
|
|
* Session GC (garbage collection) handler. |
66
|
|
|
* @param int $max_lifetime the number of seconds after which data will be seen as 'garbage' and cleaned up. |
67
|
|
|
* @return false|int whether session is GCed successfully |
68
|
|
|
*/ |
69
|
|
|
public function gc(int $max_lifetime): int|false |
70
|
|
|
{ |
71
|
|
|
return $this->_session->_gc($max_lifetime); |
|
|
|
|
72
|
|
|
} |
73
|
|
|
|
74
|
|
|
/** |
75
|
|
|
* Session open handler. |
76
|
|
|
* @param string $path session save path |
77
|
|
|
* @param string $name session name |
78
|
|
|
* @return bool whether session is opened successfully |
79
|
|
|
*/ |
80
|
|
|
public function open(string $path, string $name): bool |
81
|
|
|
{ |
82
|
|
|
return $this->_session->_open($path, $name); |
83
|
|
|
} |
84
|
|
|
|
85
|
|
|
/** |
86
|
|
|
* Session read handler. |
87
|
|
|
* @param string $id session ID |
88
|
|
|
* @return false|string the session data |
89
|
|
|
*/ |
90
|
|
|
public function read(string $id): string|false |
91
|
|
|
{ |
92
|
|
|
return $this->_session->_read($id); |
93
|
|
|
} |
94
|
|
|
|
95
|
|
|
/** |
96
|
|
|
* Session write handler. |
97
|
|
|
* @param string $id session ID |
98
|
|
|
* @param string $data session data |
99
|
|
|
* @return bool whether session write is successful |
100
|
|
|
*/ |
101
|
|
|
public function write(string $id, string $data): bool |
102
|
|
|
{ |
103
|
|
|
return $this->_session->_write($id, $data); |
104
|
|
|
} |
105
|
|
|
} |
106
|
|
|
|