123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138 |
- <?php
- namespace Predis\Session;
- use SessionHandlerInterface;
- use Predis\ClientInterface;
- class SessionHandler implements SessionHandlerInterface
- {
- protected $client;
- protected $ttl;
-
- public function __construct(ClientInterface $client, Array $options = array())
- {
- $this->client = $client;
- $this->ttl = (int) (isset($options['gc_maxlifetime']) ? $options['gc_maxlifetime'] : ini_get('session.gc_maxlifetime'));
- }
-
- public function register()
- {
- if (version_compare(PHP_VERSION, '5.4.0') >= 0) {
- session_set_save_handler($this, true);
- } else {
- session_set_save_handler(
- array($this, 'open'),
- array($this, 'close'),
- array($this, 'read'),
- array($this, 'write'),
- array($this, 'destroy'),
- array($this, 'gc')
- );
- }
- }
-
- public function open($save_path, $session_id)
- {
-
- return true;
- }
-
- public function close()
- {
-
- return true;
- }
-
- public function gc($maxlifetime)
- {
-
- return true;
- }
-
- public function read($session_id)
- {
- if ($data = $this->client->get($session_id)) {
- return $data;
- }
- return '';
- }
-
- public function write($session_id, $session_data)
- {
- $this->client->setex($session_id, $this->ttl, $session_data);
- return true;
- }
-
- public function destroy($session_id)
- {
- $this->client->del($session_id);
- return true;
- }
-
- public function getClient()
- {
- return $this->client;
- }
-
- public function getMaxLifeTime()
- {
- return $this->ttl;
- }
- }
|