Skip to content

Commit

Permalink
Refs matomo-org#4683 Refactor this little bit
Browse files Browse the repository at this point in the history
  • Loading branch information
mattab committed Feb 18, 2014
1 parent 83b11af commit 96cb532
Showing 1 changed file with 19 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -412,6 +412,10 @@ class UserAgentParserEnhanced
protected $brand = '';
protected $model = '';
protected $debug = false;

/**
* @var \Piwik\CacheFile
*/
protected $cache = null;

public function __construct($userAgent)
Expand All @@ -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;
}
Expand All @@ -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;
}
Expand All @@ -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;
}
Expand All @@ -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;
}
Expand Down Expand Up @@ -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;
}

}

0 comments on commit 96cb532

Please sign in to comment.