예제 #1
0
 /**
  * 返回配置缓存
  * 
  * @param string $alias 配置保存用的名字
  * @param string $append 配置追加的配置
  * @param AbstractWindCache $cache 配置保存的缓存介质
  * @return array
  */
 private function getCache($alias, $append, $cache)
 {
     if (!$append) {
         return $cache->get($alias);
     }
     if (isset($this->configs[$alias])) {
         return $this->configs[$alias];
     }
     $this->configs = $cache->get($append);
     return isset($this->configs[$alias]) ? $this->configs[$alias] : array();
 }
 /**
  * 创建并运行当前应用
  * 
  * 配合过滤链策略部署,可以通过{@see AbstractWindFrontController::registeFilter}
  * 方法注册过滤器,当应用被执行时会判断当前时候有初始化过滤链对象,并选择是否是通过过滤链方式执行应用
  * @return void
  */
 protected function _run()
 {
     $application = $this->createApplication();
     if ($this->_chain !== null) {
         $this->_chain->setCallBack(array($application, 'run'), array(true));
         $this->_chain->getHandler()->handle($this);
     } else {
         $application->run($application->getConfig('filters'));
     }
     restore_error_handler();
     restore_exception_handler();
     $this->_app->getResponse()->sendResponse();
     $this->_app->getWindFactory()->executeDestroyMethod();
     if ($this->_cache !== null && $this->_cached === false) {
         $this->_cache->set('factory', $this->_factory);
         $this->_cache->set('classes', Wind::$_classes);
         $this->_cache->set('imports', Wind::$_imports);
         $this->_cache->set('config', $this->_config);
     }
 }
예제 #3
0
 public function setConfig($config)
 {
     parent::setConfig($config);
     $this->table = $this->getConfig('table-name', '', 'cache', $config);
     $this->keyField = $this->getConfig('field-key', '', 'key', $config);
     $this->valueField = $this->getConfig('field-value', '', 'value', $config);
     $this->expireField = $this->getConfig('field-expire', '', 'expire', $config);
 }
예제 #4
0
 public function setConfig($config = array())
 {
     if (!$config) {
         return false;
     }
     parent::setConfig($config);
     $this->authUser = $this->getConfig('user');
     $this->authPwd = $this->getConfig('pwd');
 }
예제 #5
0
 public function setConfig($config)
 {
     parent::setConfig($config);
     $auth = $this->getConfig('auth', '', '');
     if ($auth && true !== $this->redis->auth($auth)) {
         throw new WindCacheException('Authenticate the redis connection error');
     }
     $servers = $this->getConfig('servers', '', array());
     $defaultServer = array('host' => '', 'port' => 6379, 'timeout' => 0, 'pconn' => false, 'persistent_id' => '');
     foreach ((array) $servers as $server) {
         if (!is_array($server)) {
             throw new WindCacheException('The redis config is incorrect');
         }
         $args = array_merge($defaultServer, $server);
         if (!isset($server['host'])) {
             throw new WindCacheException('The redis server ip address is not exist');
         }
         $method = $args['pconn'] === true ? 'pconnect' : 'connect';
         $m_args = array($args['host'], $args['port'], $args['timeout']);
         //如果是长链接,则会存在一个长链接的ID号
         $args['pconn'] === true && $args['persistent_id'] && ($m_args[] = $args['persistent_id']);
         call_user_func_array(array($this->redis, $method), $m_args);
     }
 }
예제 #6
0
 public function setConfig($config)
 {
     parent::setConfig($config);
     $this->setCacheDir($this->getConfig('dir'));
     $this->setCacheFileSuffix($this->getConfig('suffix', '', 'txt'));
     $this->setCacheDirectoryLevel($this->getConfig('dir-level', '', 0));
 }
예제 #7
0
 public function setConfig($config)
 {
     parent::setConfig($config);
     $servers = $this->getConfig('servers', '', array());
     foreach ((array) $servers as $server) {
         if (!is_array($server)) {
             throw new WindException('The memcache config is incorrect');
         }
         if (!isset($server['host'])) {
             throw new WindException('The memcache server ip address is not exist');
         }
         if (!isset($server['port'])) {
             throw new WindException('The memcache server port is not exist');
         }
         $this->memcache->addServer($server['host'], $server['port'], isset($server['weight']) ? $server['weight'] : null);
     }
 }
예제 #8
0
 public function setConfig($config)
 {
     parent::setConfig($config);
     $this->compress = $this->getConfig('compress', '', '0');
     $servers = $this->getConfig('servers', '', array());
     $defaultServer = array('host' => '', 'port' => '', 'pconn' => true, 'weight' => 1, 'timeout' => 1, 'retry' => 15, 'status' => true, 'fcallback' => null);
     foreach ((array) $servers as $server) {
         if (!is_array($server)) {
             throw new WindCacheException('[cache.strategy.WindMemCache.setConfig] The memcache config is incorrect');
         }
         $args = array_merge($defaultServer, $server);
         if (empty($server['host'])) {
             throw new WindCacheException('[cache.strategy.WindMemCache.setConfig] The memcache server ip address is not exist');
         }
         if (empty($server['port'])) {
             throw new WindCacheException('[cache.strategy.WindMemCache.setConfig] The memcache server port is not exist');
         }
         $this->memcache->addServer($args['host'], $args['port'], $args['pconn'], $args['weight'], $args['timeout'], $args['retry'], $args['status'], $args['fcallback']);
     }
 }