示例#1
0
 /**
  * Phalcon\Session\Adapter\Aerospike constructor
  *
  * @param array $options Constructor options
  * @throws Exception
  */
 public function __construct(array $options)
 {
     if (!isset($options['hosts']) || !is_array($options['hosts'])) {
         throw new Exception('No hosts given in options');
     }
     if (isset($options['namespace'])) {
         $this->namespace = $options['namespace'];
     }
     if (isset($options['prefix'])) {
         $this->prefix = $options['prefix'];
     }
     if (isset($options['lifetime'])) {
         $this->lifetime = $options['lifetime'];
     }
     $persistent = false;
     if (isset($options['persistent'])) {
         $persistent = (bool) $options['persistent'];
     }
     $opts = [];
     if (isset($options['options']) && is_array($options['options'])) {
         $opts = $options['options'];
     }
     $this->db = new AerospikeDb(['hosts' => $options['hosts']], $persistent, $opts);
     if (!$this->db->isConnected()) {
         throw new Exception(sprintf("Aerospike failed to connect [%s]: %s", $this->db->errorno(), $this->db->error()));
     }
     parent::__construct($options);
     session_set_save_handler([$this, 'open'], [$this, 'close'], [$this, 'read'], [$this, 'write'], [$this, 'destroy'], [$this, 'gc']);
 }