示例#1
0
文件: Xcache.php 项目: rexmac/zf2
 /**
  * Constructor
  *
  * @param  array $options associative array of options
  * @throws \Zend\Cache\Exception
  * @return void
  */
 public function __construct(array $options = array())
 {
     if (!extension_loaded('xcache')) {
         Cache\Cache::throwException('The xcache extension must be loaded for using this backend !');
     }
     parent::__construct($options);
 }
示例#2
0
 /**
  * Constructor
  *
  * @param  array $options Associative array of options
  * @throws Zend_cache_Exception
  * @return void
  */
 public function __construct(array $options = array())
 {
     parent::__construct($options);
     if ($this->_options['cache_db_complete_path'] === null) {
         Cache\Cache::throwException('cache_db_complete_path option has to set');
     }
     if (!extension_loaded('sqlite')) {
         Cache\Cache::throwException("Cannot use SQLite storage because the 'sqlite' extension is not loaded in the current PHP environment");
     }
     $this->_getConnection();
 }
示例#3
0
文件: ZendPlatform.php 项目: hjr3/zf2
 /**
  * Constructor
  * Validate that the Zend Platform is loaded and licensed
  *
  * @param  array $options Associative array of options
  * @throws \Zend\Cache\Exception
  * @return void
  */
 public function __construct(array $options = array())
 {
     if (!function_exists('accelerator_license_info')) {
         Cache\Cache::throwException('The Zend Platform extension must be loaded for using this backend !');
     }
     if (!function_exists('accelerator_get_configuration')) {
         $licenseInfo = accelerator_license_info();
         Cache\Cache::throwException('The Zend Platform extension is not loaded correctly: ' . $licenseInfo['failure_reason']);
     }
     $accConf = accelerator_get_configuration();
     if (@(!$accConf['output_cache_licensed'])) {
         Cache\Cache::throwException('The Zend Platform extension does not have the proper license to use content caching features');
     }
     if (@(!$accConf['output_cache_enabled'])) {
         Cache\Cache::throwException('The Zend Platform content caching feature must be enabled for using this backend, set the \'zend_accelerator.output_cache_enabled\' directive to On !');
     }
     if (!is_writable($accConf['output_cache_dir'])) {
         Cache\Cache::throwException('The cache copies directory \'' . ini_get('zend_accelerator.output_cache_dir') . '\' must be writable !');
     }
     parent::__construct($options);
 }
示例#4
0
文件: Memcached.php 项目: rexmac/zf2
 /**
  * Constructor
  *
  * @param array $options associative array of options
  * @throws \Zend\Cache\Exception
  * @return void
  */
 public function __construct(array $options = array())
 {
     if (!extension_loaded('memcache')) {
         Cache\Cache::throwException('The memcache extension must be loaded for using this backend !');
     }
     parent::__construct($options);
     if (isset($this->_options['servers'])) {
         $value = $this->_options['servers'];
         if (isset($value['host'])) {
             // in this case, $value seems to be a simple associative array (one server only)
             $value = array(0 => $value);
             // let's transform it into a classical array of associative arrays
         }
         $this->setOption('servers', $value);
     }
     $this->_memcache = new \Memcache();
     foreach ($this->_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;
         }
         if (!array_key_exists('status', $server)) {
             $server['status'] = self::DEFAULT_STATUS;
         }
         if (!array_key_exists('failure_callback', $server)) {
             $server['failure_callback'] = self::DEFAULT_FAILURE_CALLBACK;
         }
         if ($this->_options['compatibility']) {
             // No status for compatibility mode (#ZF-5887)
             $this->_memcache->addServer($server['host'], $server['port'], $server['persistent'], $server['weight'], $server['timeout'], $server['retry_interval']);
         } else {
             $this->_memcache->addServer($server['host'], $server['port'], $server['persistent'], $server['weight'], $server['timeout'], $server['retry_interval'], $server['status'], $server['failure_callback']);
         }
     }
 }
示例#5
0
文件: File.php 项目: hjr3/zf2
 /**
  * Constructor
  *
  * @param  array $options associative array of options
  * @throws \Zend\Cache\Exception
  * @return void
  */
 public function __construct(array $options = array())
 {
     parent::__construct($options);
     if ($this->_options['cache_dir'] !== null) {
         // particular case for this option
         $this->setCacheDir($this->_options['cache_dir']);
     } else {
         $this->setCacheDir(self::getTmpDir() . DIRECTORY_SEPARATOR, false);
     }
     if (isset($this->_options['file_name_prefix'])) {
         // particular case for this option
         if (!preg_match('~^[a-zA-Z0-9_]+$~D', $this->_options['file_name_prefix'])) {
             Cache\Cache::throwException('Invalid file_name_prefix : must use only [a-zA-Z0-9_]');
         }
     }
     if ($this->_options['metadatas_array_max_size'] < 10) {
         Cache\Cache::throwException('Invalid metadatas_array_max_size, must be > 10');
     }
     if (isset($options['hashed_directory_umask']) && is_string($options['hashed_directory_umask'])) {
         // See #ZF-4422
         $this->_options['hashed_directory_umask'] = octdec($this->_options['hashed_directory_umask']);
     }
     if (isset($options['cache_file_umask']) && is_string($options['cache_file_umask'])) {
         // See #ZF-4422
         $this->_options['cache_file_umask'] = octdec($this->_options['cache_file_umask']);
     }
 }
示例#6
0
文件: TwoLevels.php 项目: hjr3/zf2
 /**
  * Constructor
  *
  * @param  array $options Associative array of options
  * @throws \Zend\Cache\Exception
  * @return void
  */
 public function __construct(array $options = array())
 {
     parent::__construct($options);
     if ($this->_options['slow_backend'] === null) {
         Cache\Cache::throwException('slow_backend option has to set');
     }
     if ($this->_options['fast_backend'] === null) {
         Cache\Cache::throwException('fast_backend option has to set');
     }
     $this->_slowBackend = Cache\Cache::_makeBackend($this->_options['slow_backend'], $this->_options['slow_backend_options'], $this->_options['slow_backend_custom_naming'], $this->_options['slow_backend_autoload']);
     $this->_fastBackend = Cache\Cache::_makeBackend($this->_options['fast_backend'], $this->_options['fast_backend_options'], $this->_options['fast_backend_custom_naming'], $this->_options['fast_backend_autoload']);
     if (!in_array('Zend_Cache_Backend_ExtendedInterface', class_implements($this->_slowBackend))) {
         Cache\Cache::throwException('slow_backend must implement the Zend_Cache_Backend_ExtendedInterface interface');
     }
     if (!in_array('Zend_Cache_Backend_ExtendedInterface', class_implements($this->_fastBackend))) {
         Cache\Cache::throwException('fast_backend must implement the Zend_Cache_Backend_ExtendedInterface interface');
     }
     $this->_slowBackend->setDirectives($this->_directives);
     $this->_fastBackend->setDirectives($this->_directives);
 }