Exemple #1
0
 /**
  * Phalcon\Cache\Backend\Redis constructor
  *
  * @param \Phalcon\Cache\FrontendInterface $frontend
  * @param array $options
  * @throws \Phalcon\Cache\Exception
  */
 public function __construct($frontend, $options = null)
 {
     if (!isset($options['redis'])) {
         throw new Exception("Parameter 'redis' is required");
     }
     parent::__construct($frontend, $options);
 }
Exemple #2
0
 /**
  * Phalcon\Cache\Backend\Memcache\Memcached constructor
  *
  * @param \Phalcon\Cache\FrontendInterface $frontend
  * @param array $options
  */
 public function __construct($frontend, $options = null)
 {
     $this->_memcache = new NativeMemcache();
     if (!isset($options['servers'])) {
         $options['servers'] = array(array('host' => self::DEFAULT_HOST));
     }
     foreach ($options['servers'] as $server) {
         if (!array_key_exists('port', $server)) {
             $server['port'] = self::DEFAULT_PORT;
         }
         if (!array_key_exists('persistent', $server)) {
             $server['persistent'] = self::DEFAULT_PERSISTENT;
         }
         if (!array_key_exists('weight', $server)) {
             $server['weight'] = self::DEFAULT_WEIGHT;
         }
         if (!array_key_exists('timeout', $server)) {
             $server['timeout'] = self::DEFAULT_TIMEOUT;
         }
         if (!array_key_exists('retry_interval', $server)) {
             $server['retry_interval'] = self::DEFAULT_RETRY_INTERVAL;
         }
         $this->_memcache->addServer($server['host'], $server['port'], $server['persistent'], $server['weight'], $server['timeout'], $server['retry_interval']);
     }
     if (!isset($options['tracking'])) {
         $options['tracking'] = self::DEFAULT_TRACKING;
     }
     if (!isset($options['tracking_key'])) {
         $options['tracking_key'] = self::DEFAULT_TRACKING_KEY;
     }
     parent::__construct($frontend, $options);
 }
Exemple #3
0
 /**
  * \Phalcon\Cache\Backend\File constructor
  *
  * @param \Phalcon\Cache\FrontendInterface $frontend
  * @param array $options
  * @throws Exception
  */
 public function __construct($frontend, $options = null)
 {
     if (is_array($options) === false || isset($options['cacheDir']) === false) {
         throw new Exception('Cache directory must be specified with the option cacheDir');
     }
     parent::__construct($frontend, $options);
 }
Exemple #4
0
 /**
  * Phalcon\Cache\Backend\Database constructor
  *
  * @param Phalcon\Cache\FrontendInterface $frontend
  * @param array $options
  */
 public function __construct($frontend, $options = array())
 {
     if (!isset($options['db'])) {
         throw new Exception("Parameter 'db' is required");
     }
     if (!isset($options['table'])) {
         throw new Exception("Parameter 'table' is required");
     }
     parent::__construct($frontend, $options);
 }
Exemple #5
0
 /**
  * \Phalcon\Cache\Backend\Xcache constructor
  *
  * @param \Phalcon\Cache\FrontendInterface $frontend
  * @param array|null $options
  */
 public function __construct($frontend, $options = null)
 {
     if (is_array($options) === false) {
         $options = array();
     }
     if (isset($options['statsKey']) === false) {
         $options['statsKey'] = '_PHCX';
     }
     parent::__construct($frontend, $options);
 }
Exemple #6
0
 /**
  * {@inheritdoc}
  *
  * @param  FrontendInterface $frontend
  * @param  array             $options
  * @throws Exception
  */
 public function __construct(FrontendInterface $frontend, array $options)
 {
     if (!isset($options['db']) || !$options['db'] instanceof DbAdapterInterface) {
         throw new Exception('Parameter "db" is required and it must be an instance of Phalcon\\Acl\\AdapterInterface');
     }
     if (!isset($options['table']) || empty($options['table']) || !is_string($options['table'])) {
         throw new Exception("Parameter 'table' is required and it must be a non empty string");
     }
     $this->db = $options['db'];
     $this->table = $this->db->escapeIdentifier($options['table']);
     unset($options['db'], $options['table']);
     parent::__construct($frontend, $options);
 }
Exemple #7
0
 /**
  * \Phalcon\Cache\Backend\Mongo constructor
  *
  * @param \Phalcon\Cache\FrontendInterface $frontend
  * @param array|null $options
  * @throws Exception
  */
 public function __construct($frontend, $options = null)
 {
     if (is_array($options) === false) {
         $options = array();
     }
     if (isset($options['mongo']) === false && isset($options['server']) === false) {
         throw new Exception('The parameter \'server\' is required');
     }
     if (isset($options['db']) === false) {
         throw new Exception('The parameter \'db\' is required');
     }
     if (isset($options['collection']) === false) {
         throw new Exception("The parameter 'collection' is required");
     }
     parent::__construct($frontend, $options);
 }
Exemple #8
0
 /**
  * \Engine\Cache\Backend\Redis constructor
  *
  * @param \Phalcon\Cache\FrontendInterface $frontend
  * @param array $options
  * @throws \Phalcon\Cache\Exception
  */
 public function __construct($frontend, $options = null)
 {
     if (!isset($options['redis'])) {
         throw new \Exception("Parameter 'redis' is required");
     }
     if (is_array($options['redis'])) {
         if (!isset($options['redis']['host'])) {
             throw new \Exception("Parameter 'redis host' is required");
         }
         if (!isset($options['redis']['port'])) {
             throw new \Exception("Parameter 'redis port' is required");
         }
         $redis = new \Redis();
         $redis->connect($options['redis']['host'], $options['redis']['port']);
         $options['redis'] = $redis;
     }
     parent::__construct($frontend, $options);
 }
Exemple #9
0
 /**
  * \Phalcon\Cache\Backend\Memcache constructor
  *
  * @param \Phalcon\Cache\FrontendInterface $frontend
  * @param array|null $options
  */
 public function __construct($frontend, $options = null)
 {
     if (is_null($options) === true) {
         $options = array();
     }
     if (isset($options['host']) === false) {
         $options['host'] = '127.0.0.1';
     }
     if (isset($options['port']) === false) {
         $options['port'] = '11211';
     }
     if (isset($options['persistent']) === false) {
         $options['persistent'] = false;
     }
     if (isset($options['statsKey']) === false) {
         $options['statsKey'] = '_PHCM';
     }
     parent::__construct($frontend, $options);
 }
Exemple #10
0
 /**
  * @param FrontendInterface $frontend
  * @param array $options
  */
 public function __construct($frontend, $options = array())
 {
     $this->_backend = new MemcachedDriver(self::DRIVER_PERSISTENCE_ID);
     if (!isset($options['servers'])) {
         $options['servers'] = array(array('host' => self::DEFAULT_HOST));
     }
     foreach ($options['servers'] as $server) {
         if (!array_key_exists('port', $server)) {
             $server['port'] = self::DEFAULT_PORT;
         }
         if (!array_key_exists('weight', $server)) {
             $server['weight'] = self::DEFAULT_WEIGHT;
         }
         $this->_backend->addServer($server['host'], $server['port'], $server['weight']);
     }
     if (isset($options['client']) && is_array($options['client'])) {
         $this->_backend->setOptions($options['client']);
     }
     unset($options['servers'], $options['client']);
     parent::__construct($frontend, $options);
 }
Exemple #11
0
 /**
  * Phalcon\Cache\Backend\Aerospike constructor
  *
  * @param  FrontendInterface $frontend Frontend Interface
  * @param  array             $options  Constructor options
  * @throws Exception
  */
 public function __construct(FrontendInterface $frontend, 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'];
     }
     $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($frontend, $options);
 }