1 | <?php |
||
10 | class Redis implements SaveHandlerInterface |
||
11 | { |
||
12 | |||
13 | /** |
||
14 | * @var \Redis |
||
15 | */ |
||
16 | protected $redis; |
||
17 | |||
18 | /** |
||
19 | * Session Save Path |
||
20 | * |
||
21 | * @var string |
||
22 | */ |
||
23 | protected $sessionSavePath; |
||
24 | |||
25 | /** |
||
26 | * Session Name |
||
27 | * |
||
28 | * @var string |
||
29 | */ |
||
30 | protected $sessionName; |
||
31 | |||
32 | /** |
||
33 | * Lifetime |
||
34 | * @var int |
||
35 | */ |
||
36 | protected $lifetime; |
||
37 | |||
38 | /** |
||
39 | * Constructor |
||
40 | * @param string $host |
||
41 | * @param string $port |
||
42 | * @param string $password |
||
43 | */ |
||
44 | public function __construct($host, $port, $password) |
||
50 | |||
51 | /** |
||
52 | * Open Session - retrieve resources |
||
53 | * |
||
54 | * @param string $savePath |
||
55 | * @param string $name |
||
56 | */ |
||
57 | public function open($savePath, $name) |
||
63 | |||
64 | /** |
||
65 | * Close Session - free resources |
||
66 | * |
||
67 | */ |
||
68 | public function close() |
||
72 | |||
73 | /** |
||
74 | * Read session data |
||
75 | * |
||
76 | * @param string $identifier |
||
77 | * @return bool|string |
||
78 | */ |
||
79 | public function read($identifier) |
||
83 | |||
84 | /** |
||
85 | * Read sessions for user |
||
86 | * @param $userId |
||
87 | * @return array |
||
88 | */ |
||
89 | public function readByUser($userId) |
||
93 | |||
94 | /** |
||
95 | * Write Session - commit data to resource |
||
96 | * |
||
97 | * @param string $identifier |
||
98 | * @param mixed $data |
||
99 | */ |
||
100 | public function write($identifier, $data) |
||
108 | |||
109 | /** |
||
110 | * Write session ids for user |
||
111 | * @param $sessionId |
||
112 | * @param $userId |
||
113 | */ |
||
114 | public function writeByUser($sessionId, $userId) |
||
118 | |||
119 | /** |
||
120 | * Destroy Session and remove data from user's container |
||
121 | * @param string $sessionId |
||
122 | * @param null $userId |
||
123 | */ |
||
124 | public function destroy($sessionId, $userId = null) |
||
139 | |||
140 | /** |
||
141 | * Destroy all sessions by user |
||
142 | * @param $userId |
||
143 | */ |
||
144 | public function destroyByUser($userId) |
||
155 | |||
156 | /** |
||
157 | * Add prefix for session's key |
||
158 | * @param $sessionId |
||
159 | * @return string |
||
160 | */ |
||
161 | protected function getSessionKey($sessionId) |
||
165 | |||
166 | /** |
||
167 | * Add prefix for user's key |
||
168 | * @param $userId |
||
169 | * @return string |
||
170 | */ |
||
171 | protected function getUserKey($userId) |
||
175 | |||
176 | /** |
||
177 | * Garbage Collection - remove old session data older |
||
178 | * than $maxlifetime (in seconds) |
||
179 | * |
||
180 | * @param int $maxlifetime |
||
181 | */ |
||
182 | public function gc($maxlifetime) |
||
186 | } |
||
187 |
This check looks for assignments to scalar types that may be of the wrong type.
To ensure the code behaves as expected, it may be a good idea to add an explicit type cast.