1 | <?php |
||
8 | class MongodbSessionHandler implements \SessionHandlerInterface |
||
9 | { |
||
10 | /** |
||
11 | * Session collection |
||
12 | * @var \MongoDB\Collection |
||
13 | */ |
||
14 | protected $collection; |
||
15 | |||
16 | /** |
||
17 | * Never store changes to a session |
||
18 | * @var boolean |
||
19 | */ |
||
20 | protected $readonly = false; |
||
21 | |||
22 | |||
23 | /** |
||
24 | * Class constructor |
||
25 | * |
||
26 | * @param \MongoDB\Collection $collection |
||
27 | * @param string $mode 'w' for read-write or 'r' for read-only |
||
28 | */ |
||
29 | 10 | public function __construct(\MongoDB\Collection $collection, $mode = 'w') |
|
34 | |||
35 | /** |
||
36 | * Initialize session |
||
37 | * @link http://php.net/manual/en/sessionhandlerinterface.open.php |
||
38 | * |
||
39 | * @param string $save_path The path where to store/retrieve the session. |
||
40 | * @param string $name The session name. |
||
41 | * @return boolean |
||
42 | */ |
||
43 | 1 | public function open($save_path, $name) |
|
47 | |||
48 | /** |
||
49 | * Close the session |
||
50 | * @link http://php.net/manual/en/sessionhandlerinterface.close.php |
||
51 | * |
||
52 | * @return boolean |
||
53 | */ |
||
54 | 1 | public function close() |
|
55 | { |
||
56 | 1 | unset($_SESSION); |
|
57 | 1 | return true; |
|
58 | } |
||
59 | |||
60 | /** |
||
61 | * (PHP 5 >= 5.4.0)<br/> |
||
62 | * Read session data |
||
63 | * @link http://php.net/manual/en/sessionhandlerinterface.read.php |
||
64 | * @param string $session_id The session id. |
||
65 | * @return string |
||
66 | */ |
||
67 | 2 | public function read($session_id) |
|
83 | |||
84 | /** |
||
85 | * (PHP 5 >= 5.4.0)<br/> |
||
86 | * Write session data |
||
87 | * @link http://php.net/manual/en/sessionhandlerinterface.write.php |
||
88 | * @param string $session_id The session id. |
||
89 | * @param string $session_data The encoded session data. |
||
90 | * @return boolean |
||
91 | */ |
||
92 | 2 | public function write($session_id, $session_data) |
|
102 | |||
103 | /** |
||
104 | * (PHP 5 >= 5.4.0)<br/> |
||
105 | * Destroy a session |
||
106 | * @link http://php.net/manual/en/sessionhandlerinterface.destroy.php |
||
107 | * @param string $session_id The session ID being destroyed. |
||
108 | * @return boolean |
||
109 | */ |
||
110 | 2 | public function destroy($session_id) |
|
119 | |||
120 | /** |
||
121 | * This method must be implemented for the interface, but isn't used. Instead use a MongoDB tty index. |
||
122 | * @link http://php.net/manual/en/sessionhandlerinterface.gc.php |
||
123 | * @link https://docs.mongodb.com/manual/core/index-ttl/ |
||
124 | * |
||
125 | * @param int $maxlifetime |
||
126 | */ |
||
127 | 1 | public function gc($maxlifetime) |
|
130 | |||
131 | /** |
||
132 | * This callback is executed when a new session ID is required. No parameters are provided, and the return value |
||
133 | * should be a string that is a valid session ID for your handler. |
||
134 | * |
||
135 | * @return string |
||
136 | */ |
||
137 | 1 | public function create_sid() |
|
144 | } |
||
145 |