diff --git a/plugins/DevicesDetection/UserAgentParserEnhanced/UserAgentParserEnhanced.php b/plugins/DevicesDetection/UserAgentParserEnhanced/UserAgentParserEnhanced.php index 63a67a66ad2..f7b23b7d6ba 100644 --- a/plugins/DevicesDetection/UserAgentParserEnhanced/UserAgentParserEnhanced.php +++ b/plugins/DevicesDetection/UserAgentParserEnhanced/UserAgentParserEnhanced.php @@ -412,6 +412,10 @@ class UserAgentParserEnhanced protected $brand = ''; protected $model = ''; protected $debug = false; + + /** + * @var \Piwik\CacheFile + */ protected $cache = null; public function __construct($userAgent) @@ -422,12 +426,8 @@ public function __construct($userAgent) protected function getOsRegexes() { static $regexOs; - if (empty($regexOs)) { - $regexOs = $this->getParsedYmlFromCache('os'); - } - if (empty($regexOs)) { - $regexOs = Spyc::YAMLLoad(dirname(__FILE__) . self::$regexesDir . self::$osRegexesFile); - $this->saveParsedYmlInCache('os', $regexOs); + if(empty($regexOs)) { + $regexOs = $this->getRegexList('os', self::$osRegexesFile); } return $regexOs; } @@ -436,11 +436,7 @@ protected function getBrowserRegexes() { static $regexBrowser; if (empty($regexBrowser)) { - $regexBrowser = $this->getParsedYmlFromCache('browser'); - } - if (empty($regexBrowser)) { - $regexBrowser = Spyc::YAMLLoad(dirname(__FILE__) . self::$regexesDir . self::$browserRegexesFile); - $this->saveParsedYmlInCache('browser', $regexBrowser); + $regexBrowser = $this->getRegexList('browser', self::$browserRegexesFile); } return $regexBrowser; } @@ -449,11 +445,7 @@ protected function getMobileRegexes() { static $regexMobile; if (empty($regexMobile)) { - $regexMobile = $this->getParsedYmlFromCache('mobile'); - } - if (empty($regexMobile)) { - $regexMobile = Spyc::YAMLLoad(dirname(__FILE__) . self::$regexesDir . self::$mobileRegexesFile); - $this->saveParsedYmlInCache('mobile', $regexMobile); + $regexMobile = $this->getRegexList('mobile', self::$mobileRegexesFile); } return $regexMobile; } @@ -462,11 +454,7 @@ protected function getTelevisionRegexes() { static $regexTvs; if (empty($regexTvs)) { - $regexTvs = $this->getParsedYmlFromCache('tv'); - } - if (empty($regexTvs)) { - $regexTvs = Spyc::YAMLLoad(dirname(__FILE__) . self::$regexesDir . self::$televisionRegexesFile); - $this->saveParsedYmlInCache('tv', $regexTvs); + $regexTvs = $this->getRegexList('tv', self::$televisionRegexesFile); } return $regexTvs; } @@ -938,4 +926,14 @@ static public function getInfoFromUserAgent($ua) return $processed; } + protected function getRegexList($type, $regexesFile) + { + $regexList = $this->getParsedYmlFromCache($type); + if (empty($regexList)) { + $regexList = Spyc::YAMLLoad(dirname(__FILE__) . self::$regexesDir . $regexesFile); + $this->saveParsedYmlInCache($type, $regexList); + } + return $regexList; + } + }