Guest User

Untitled

a guest
Jul 7th, 2018
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.72 KB | None | 0 0
  1. class User_Session_Couchbase_Storage extends User_Session_Storage_Interface
  2. {
  3.     private $exist=true;
  4.     private static $host,$user,$password,$bucket,$isConnected=false,$connection;
  5.  
  6.     function __construct($host,$user,$password,$bucket)
  7.     {
  8.         self::setConnection($host,$user,$password,$bucket);
  9.     }
  10.    
  11.     static function setConnection($host,$user,$password,$bucket)
  12.     {
  13.         self::$host = $host;
  14.         self::$user = $user;
  15.         self::$password = $password;
  16.         self::$bucket = $bucket;
  17.        
  18.         if(!self::$isConnected) {
  19.             self::$connection  = new Couchbase(self::$host, self::$user, self::$password, self::$bucket);
  20.             self::$isConnected = true;
  21.         }
  22.     }
  23.  
  24.     public function get($id)
  25.     {
  26.         if(!$this->exist) {
  27.             $data = self::$connection->get($id);
  28.             if(self::$connection->getResultCode() == COUCHBASE_KEY_ENOENT){
  29.                 $this->exist = false;
  30.             } else {
  31.                 $this->exist = true;
  32.                 return $data;
  33.             }
  34.         }
  35.     }
  36.  
  37.     public function set($id,$data,$time)
  38.     {
  39.         if(strlen($data) > 6) {
  40.             $this->get($id);
  41.            
  42.             if(!$this->exist) {
  43.                 self::$connection->add($id,$data,1296000);
  44.             } else {
  45.                 self::$connection->replace($id,$data,1296000);
  46.             }
  47.         }
  48.     }
  49.    
  50.     public function create($id,$data,$time)
  51.     {
  52.         //not used
  53.     }
  54.    
  55.     public function clean($time)
  56.     {
  57.         //not used
  58.     }
  59.     public function optimize()
  60.     {
  61.         //not used
  62.     }
  63.  
  64.     public function remove($id)
  65.     {
  66.         self::$connection->delete($id);
  67.     }
  68. }
Add Comment
Please, Sign In to add comment