Ejemplo n.º 1
0
 private static function registerCache(array $options)
 {
     $_options = array();
     $cacheAdapter = isset($options['adapter']) ? $options['adapter'] : 'redis';
     if ($cacheAdapter == 'redis') {
         if (isset($options['options']['url']) && !empty($options['options']['url'])) {
             $uri = new Uri($options['options']['url']);
             $_options['redis-host'] = $uri->getHost();
             $_options['redis-port'] = $uri->getPort();
             $_options['redis-pass'] = $uri->getPass();
         } else {
             $_options['redis-host'] = isset($options['options']['host']) ? $options['options']['host'] : null;
             $_options['redis-port'] = isset($options['options']['port']) ? $options['options']['port'] : null;
             $_options['redis-pass'] = isset($options['options']['pass']) ? $options['options']['pass'] : null;
         }
         $_options['redis-timeout'] = isset($options['options']['timeout']) ? $options['options']['timeout'] : null;
     } elseif ($cacheAdapter == 'predis') {
         $_options['predis-options'] = isset($options['options']) ? $options['options'] : null;
         $_options['predis-parameters'] = isset($options['parameters']) ? $options['parameters'] : null;
     } else {
         throw new Exception("A valid cache system is required. Given: {$cacheAdapter}");
     }
     CacheTrait::addCache($cacheAdapter, $_options);
 }
Ejemplo n.º 2
0
 private function registerCache()
 {
     $cacheAdapter = $this->get(OptionsEnum::CACHE_ADAPTER);
     $options = array();
     if ($cacheAdapter == 'redis') {
         $options = array(OptionsEnum::REDIS_HOST => $this->get(OptionsEnum::REDIS_HOST), OptionsEnum::REDIS_PORT => $this->get(OptionsEnum::REDIS_PORT), OptionsEnum::REDIS_PASS => $this->get(OptionsEnum::REDIS_PASS), OptionsEnum::REDIS_TIMEOUT => $this->get(OptionsEnum::REDIS_TIMEOUT));
         $_redisUrl = $this->get(OptionsEnum::REDIS_URL);
         if (!empty($_redisUrl)) {
             $uri = new Uri($this->get(OptionsEnum::REDIS_URL));
             $options[OptionsEnum::REDIS_HOST] = $uri->getHost();
             $options[OptionsEnum::REDIS_PORT] = $uri->getPort();
             $options[OptionsEnum::REDIS_PASS] = $uri->getPass();
         }
     } elseif ($cacheAdapter == 'predis') {
         $options[OptionsEnum::PREDIS_OPTIONS] = json_decode($this->get(OptionsEnum::PREDIS_OPTIONS), true);
         $options[OptionsEnum::PREDIS_PARAMETERS] = json_decode($this->get(OptionsEnum::PREDIS_PARAMETERS), true);
     }
     try {
         CacheTrait::addCache($cacheAdapter, $options);
     } catch (\Exception $e) {
         $this->error($e->getMessage());
     }
 }