Skip to content

Commit

Permalink
♻️ Overwrite parent version method
Browse files Browse the repository at this point in the history
  • Loading branch information
jenssegers committed Jan 6, 2019
1 parent 24d53f0 commit 65756ae
Showing 1 changed file with 40 additions and 0 deletions.
40 changes: 40 additions & 0 deletions src/Agent.php
Original file line number Diff line number Diff line change
Expand Up @@ -299,6 +299,46 @@ public function isRobot($userAgent = null)
return $this->getCrawlerDetect()->isCrawler($userAgent ?: $this->userAgent);
}

public function version($propertyName, $type = self::VERSION_TYPE_STRING)
{
if (empty($propertyName)) {
return false;
}

// set the $type to the default if we don't recognize the type
if ($type !== self::VERSION_TYPE_STRING && $type !== self::VERSION_TYPE_FLOAT) {
$type = self::VERSION_TYPE_STRING;
}

$properties = self::getProperties();

// Check if the property exists in the properties array.
if (true === isset($properties[$propertyName])) {

// Prepare the pattern to be matched.
// Make sure we always deal with an array (string is converted).
$properties[$propertyName] = (array) $properties[$propertyName];

foreach ($properties[$propertyName] as $propertyMatchString) {

$propertyPattern = str_replace('[VER]', self::VER, $propertyMatchString);

// Identify and extract the version.
preg_match(sprintf('#%s#is', $propertyPattern), $this->userAgent, $match);

if (false === empty($match[1])) {
$version = ($type === self::VERSION_TYPE_FLOAT ? $this->prepareVersionNo($match[1]) : $match[1]);

return $version;
}

}

}

return false;
}

/**
* Merge multiple rules into one array.
* @param array $all
Expand Down

0 comments on commit 65756ae

Please sign in to comment.