Advertisement
Guest User

Untitled

a guest
Nov 26th, 2014
29
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.67 KB | None | 0 0
  1. <?php
  2. /**
  3.  * Piwik - free/libre analytics platform
  4.  *
  5.  * @link http://piwik.org
  6.  * @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later
  7.  *
  8.  */
  9. namespace Piwik\Plugins\QueuedTracking;
  10.  
  11. use Piwik\Tracker\Cache;
  12.  
  13. class Config
  14. {
  15.     private $cachedConfig;
  16.  
  17.     public function getRedisHost()
  18.     {
  19.         return $this->getFromTrackerCache('redisHost');
  20.     }
  21.  
  22.     public function getRedisPort()
  23.     {
  24.         return $this->getFromTrackerCache('redisPort');
  25.     }
  26.  
  27.     public function getRedisTimeout()
  28.     {
  29.         return $this->getFromTrackerCache('redisTimeout');
  30.     }
  31.  
  32.     public function getRedisPassword()
  33.     {
  34.         return $this->getFromTrackerCache('redisPassword');
  35.     }
  36.  
  37.     public function isQueueEnabled()
  38.     {
  39.         return $this->getFromTrackerCache('queueEnabled');
  40.     }
  41.  
  42.     public function getNumRequestsToProcess()
  43.     {
  44.         return $this->getFromTrackerCache('numRequestsToProcess');
  45.     }
  46.  
  47.     public function shouldProcessDuringTrackingRequest()
  48.     {
  49.         return $this->getFromTrackerCache('processDuringTrackingRequest');
  50.     }
  51.  
  52.     private function getFromTrackerCache($name)
  53.     {
  54.         $this->loadCachedConfigIfNeeded();
  55.  
  56.         $name = $this->prefix($name);
  57.  
  58.         if (array_key_exists($name, $this->cachedConfig)) {
  59.             return $this->cachedConfig[$name];
  60.         }
  61.     }
  62.  
  63.     private function loadCachedConfigIfNeeded()
  64.     {
  65.         if (is_null($this->cachedConfig)) {
  66.             $this->cachedConfig = Cache::getCacheGeneral();
  67.         }
  68.  
  69.         if (empty($this->cachedConfig)) {
  70.             $this->cachedConfig = array();
  71.         }
  72.     }
  73.  
  74.     private function prefix($optionName)
  75.     {
  76.         return 'QueuedTracking.' . $optionName;
  77.     }
  78.  
  79.     public function setTrackerCacheGeneral($cacheContent)
  80.     {
  81.         $settings = new Settings();
  82.         $cacheContent[$this->prefix('redisHost')] = $cacheContent[$settings->redisHost->getValue()];
  83.         $cacheContent[$this->prefix('redisPort')] = $cacheContent[$settings->redisPort->getValue()];
  84.         $cacheContent[$this->prefix('redisPassword')] = $cacheContent[$settings->redisPassword->getValue()];
  85.         $cacheContent[$this->prefix('redisTimeout')] = $cacheContent[$settings->redisTimeout->getValue()];
  86.         $cacheContent[$this->prefix('queueEnabled')] = $cacheContent[$settings->queueEnabled->getValue()];
  87.         $cacheContent[$this->prefix('processDuringTrackingRequest')] = $cacheContent[$settings->processDuringTrackingRequest->getValue()];
  88.         $cacheContent[$this->prefix('numRequestsToProcess')] = $cacheContent[$settings->numRequestsToProcess->getValue()];
  89.  
  90.         return $cacheContent;
  91.     }
  92.  
  93. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement