public getBrowser ( string $userAgent = null ) : stdClass | ||
$userAgent | string | the user agent string |
return | stdClass | the object containing the browsers details. Array if $return_array is set to true. |
public function getBrowser($userAgent = null)
{
if (null === $this->getCache()->getVersion()) {
// there is no active/warm cache available
throw new Exception('there is no active cache available, please run the update command');
}
// Automatically detect the useragent
if (!isset($userAgent)) {
$support = new Helper\Support($_SERVER);
$userAgent = $support->getUserAgent();
}
// try to get browser data
$formatter = $this->getParser()->getBrowser($userAgent);
// if return is still NULL, updates are disabled... in this
// case we return an empty formatter instance
if ($formatter === null) {
return $this->getFormatter()->getData();
}
return $formatter->getData();
}
/** * @dataProvider providerUserAgent * @depends testCheckProperties * @group compare * * @param string $userAgent */ public function testCompare($userAgent) { $libResult = get_browser($userAgent); $bcResult = self::$object->getBrowser($userAgent); foreach (array_keys($this->properties) as $bcProp) { if (in_array($bcProp, array('browser_name_regex', 'browser_name_pattern', 'Parent'))) { continue; } $bcProp = strtolower($bcProp); self::assertObjectHasAttribute($bcProp, $libResult, 'Actual library result does not have "' . $bcProp . '" property'); self::assertObjectHasAttribute($bcProp, $bcResult, 'Actual browscap result does not have "' . $bcProp . '" property'); $libValue = (string) $libResult->{$bcProp}; $bcValue = (string) $bcResult->{$bcProp}; self::assertSame($libValue, $bcValue, 'Expected actual "' . $bcProp . '" to be "' . $libValue . '" (was "' . $bcValue . '"; used pattern: ' . $bcResult->browser_name_pattern . ')'); } }