Author: Martin Keckeis (martin.keckeis1@gmail.com)
 protected function assertProviderResult($result, array $expectedResult)
 {
     $this->assertInstanceOf('UserAgentParser\\Model\\UserAgent', $result);
     $model = new UserAgent();
     $expectedResult = array_merge($model->toArray(), $expectedResult);
     $this->assertEquals($result->toArray(), $expectedResult);
 }
 public function parse($userAgent, array $headers = [])
 {
     $resultRaw = parse_user_agent($userAgent);
     if ($this->hasResult($resultRaw) !== true) {
         throw new Exception\NoResultFoundException('No result found for user agent: ' . $userAgent);
     }
     /*
      * Hydrate the model
      */
     $result = new Model\UserAgent();
     $result->setProviderResultRaw($resultRaw);
     /*
      * Bot detection - is currently not possible!
      */
     /*
      * hydrate the result
      */
     $this->hydrateBrowser($result->getBrowser(), $resultRaw);
     // renderingEngine not available
     // os is mixed with device informations
     // device is mixed with os
     return $result;
 }
 public function parse($userAgent, array $headers = [])
 {
     $parser = $this->getParser();
     /* @var $resultRaw \stdClass */
     $resultRaw = $parser->getBrowser($userAgent);
     /*
      * No result found?
      */
     if ($this->hasResult($resultRaw) !== true) {
         throw new NoResultFoundException('No result found for user agent: ' . $userAgent);
     }
     /*
      * Hydrate the model
      */
     $result = new Model\UserAgent();
     $result->setProviderResultRaw($resultRaw);
     /*
      * Bot detection (does only work with full_php_browscap.ini)
      */
     if ($this->isBot($resultRaw) === true) {
         $this->hydrateBot($result->getBot(), $resultRaw);
         return $result;
     }
     /*
      * hydrate the result
      */
     $this->hydrateBrowser($result->getBrowser(), $resultRaw);
     $this->hydrateRenderingEngine($result->getRenderingEngine(), $resultRaw);
     $this->hydrateOperatingSystem($result->getOperatingSystem(), $resultRaw);
     $this->hydrateDevice($result->getDevice(), $resultRaw);
     return $result;
 }
 public function parse($userAgent, array $headers = [])
 {
     $resultRaw = $this->getResult($userAgent, $headers);
     /*
      * Hydrate the model
      */
     $result = new Model\UserAgent();
     $result->setProviderResultRaw($resultRaw);
     /*
      * Bot detection
      */
     if (isset($resultRaw->IsCrawler) && $resultRaw->IsCrawler === true) {
         $this->hydrateBot($result->getBot(), $resultRaw);
         return $result;
     }
     /*
      * hydrate the result
      */
     $this->hydrateBrowser($result->getBrowser(), $resultRaw);
     $this->hydrateRenderingEngine($result->getRenderingEngine(), $resultRaw);
     $this->hydrateOperatingSystem($result->getOperatingSystem(), $resultRaw);
     $this->hydrateDevice($result->getDevice(), $resultRaw);
     return $result;
 }
 public function parse($userAgent, array $headers = [])
 {
     $resultRaw = $this->getResult($userAgent, $headers);
     /*
      * No result found?
      */
     if ($this->hasResult($resultRaw) !== true) {
         throw new Exception\NoResultFoundException('No result found for user agent: ' . $userAgent);
     }
     /*
      * Hydrate the model
      */
     $result = new Model\UserAgent();
     $result->setProviderResultRaw($resultRaw);
     /*
      * Bot detection
      */
     if ($this->isBot($resultRaw) === true) {
         $this->hydrateBot($result->getBot(), $resultRaw);
         return $result;
     }
     /*
      * hydrate the result
      */
     $this->hydrateBrowser($result->getBrowser(), $resultRaw);
     $this->hydrateRenderingEngine($result->getRenderingEngine(), $resultRaw);
     $this->hydrateOperatingSystem($result->getOperatingSystem(), $resultRaw);
     $this->hydrateDevice($result->getDevice(), $resultRaw);
     return $result;
 }
 public function parse($userAgent, array $headers = [])
 {
     $headers['User-Agent'] = $userAgent;
     $parser = $this->getParser();
     // $config = $parser->config;
     // $parser = new Parser\HD4($config);
     /*
      * No result found?
      */
     if ($parser->deviceDetect($headers) !== true) {
         throw new NoResultFoundException('No result found for user agent: ' . $userAgent);
     }
     $resultRaw = $parser->getReply();
     /*
      * No result found?
      */
     if (!isset($resultRaw['hd_specs']) || $this->hasResult($resultRaw['hd_specs']) !== true) {
         throw new NoResultFoundException('No result found for user agent: ' . $userAgent);
     }
     /*
      * Hydrate the model
      */
     $result = new Model\UserAgent();
     $result->setProviderResultRaw($resultRaw['hd_specs']);
     /*
      * hydrate the result
      */
     $this->hydrateBrowser($result->getBrowser(), $resultRaw['hd_specs']);
     // renderingEngine not available
     $this->hydrateOperatingSystem($result->getOperatingSystem(), $resultRaw['hd_specs']);
     $this->hydrateDevice($result->getDevice(), $resultRaw['hd_specs']);
     return $result;
 }
Exemplo n.º 7
0
 public function testToArray()
 {
     $ua = new UserAgent();
     $this->assertEquals(['browser' => $ua->getBrowser()->toArray(), 'renderingEngine' => $ua->getRenderingEngine()->toArray(), 'operatingSystem' => $ua->getOperatingSystem()->toArray(), 'device' => $ua->getDevice()->toArray(), 'bot' => $ua->getBot()->toArray()], $ua->toArray());
     $this->assertEquals(['browser' => $ua->getBrowser()->toArray(), 'renderingEngine' => $ua->getRenderingEngine()->toArray(), 'operatingSystem' => $ua->getOperatingSystem()->toArray(), 'device' => $ua->getDevice()->toArray(), 'bot' => $ua->getBot()->toArray(), 'providerResultRaw' => null], $ua->toArray(true));
 }
 public function parse($userAgent, array $headers = [])
 {
     $parser = $this->getParser();
     $parser->setHttpHeaders($headers);
     $parser->setUserAgent($userAgent);
     /*
      * Since Mobile_Detect to a regex comparison on every call
      * We cache it here for all checks and hydration
      */
     $browserName = $parser->browser();
     $osName = $parser->platform();
     $resultCache = ['browserName' => $browserName, 'browserVersion' => $parser->version($browserName), 'osName' => $osName, 'osVersion' => $parser->version($osName), 'deviceModel' => $parser->device(), 'isMobile' => $parser->isMobile(), 'isRobot' => $parser->isRobot(), 'botName' => $parser->robot()];
     /*
      * No result found?
      */
     if ($this->hasResult($resultCache) !== true) {
         throw new NoResultFoundException('No result found for user agent: ' . $userAgent);
     }
     /*
      * Hydrate the model
      */
     $result = new Model\UserAgent();
     $result->setProviderResultRaw($resultCache);
     /*
      * Bot detection
      */
     if ($resultCache['isRobot'] === true) {
         $this->hydrateBot($result->getBot(), $resultCache);
         return $result;
     }
     /*
      * hydrate the result
      */
     $this->hydrateBrowser($result->getBrowser(), $resultCache);
     $this->hydrateOperatingSystem($result->getOperatingSystem(), $resultCache);
     $this->hydrateDevice($result->getDevice(), $resultCache);
     return $result;
 }
Exemplo n.º 9
0
 public function parse($userAgent, array $headers = [])
 {
     $parser = $this->getParser();
     /* @var $resultRaw \UAParser\Result\Client */
     $resultRaw = $parser->parse($userAgent);
     /*
      * No result found?
      */
     if ($this->hasResult($resultRaw) !== true) {
         throw new NoResultFoundException('No result found for user agent: ' . $userAgent);
     }
     /*
      * Hydrate the model
      */
     $result = new Model\UserAgent();
     $result->setProviderResultRaw($resultRaw);
     /*
      * Bot detection
      */
     if ($this->isBot($resultRaw) === true) {
         $this->hydrateBot($result->getBot(), $resultRaw);
         return $result;
     }
     /*
      * hydrate the result
      */
     $this->hydrateBrowser($result->getBrowser(), $resultRaw->ua);
     // renderingEngine not available
     $this->hydrateOperatingSystem($result->getOperatingSystem(), $resultRaw->os);
     $this->hydrateDevice($result->getDevice(), $resultRaw->device);
     return $result;
 }
Exemplo n.º 10
0
 public function parse($userAgent, array $headers = [])
 {
     $resultRaw = $this->getParser($userAgent);
     /*
      * No result found?
      */
     if ($this->hasResult($resultRaw) !== true) {
         throw new NoResultFoundException('No result found for user agent: ' . $userAgent);
     }
     /*
      * Hydrate the model
      */
     $result = new Model\UserAgent();
     $result->setProviderResultRaw($resultRaw);
     /*
      * Bot detection
      */
     if ($this->isRealResult($resultRaw->Robot->getType()) === true) {
         $this->hydrateBot($result->getBot(), $resultRaw->Robot);
         return $result;
     }
     /*
      * hydrate the result
      */
     if ($resultRaw->Browser instanceof EndorphinDetector\Browser) {
         $this->hydrateBrowser($result->getBrowser(), $resultRaw->Browser);
     }
     if ($resultRaw->OS instanceof EndorphinDetector\OS) {
         $this->hydrateOperatingSystem($result->getOperatingSystem(), $resultRaw->OS);
     }
     if ($resultRaw->Device instanceof EndorphinDetector\Device) {
         $this->hydrateDevice($result->getDevice(), $resultRaw->Device);
     }
     return $result;
 }
 public function parse($userAgent, array $headers = [])
 {
     $browserRaw = $this->getBrowserParser($userAgent);
     $osRaw = $this->getOperatingSystemParser($userAgent);
     $deviceRaw = $this->getDeviceParser($userAgent);
     /*
      * No result found?
      */
     if ($this->hasResult($browserRaw, $osRaw, $deviceRaw) !== true) {
         throw new NoResultFoundException('No result found for user agent: ' . $userAgent);
     }
     /*
      * Hydrate the model
      */
     $result = new Model\UserAgent();
     $result->setProviderResultRaw(['browser' => $browserRaw, 'operatingSystem' => $osRaw, 'device' => $deviceRaw]);
     /*
      * Bot detection
      */
     if ($browserRaw->isRobot() === true) {
         $bot = $result->getBot();
         $bot->setIsBot(true);
         return $result;
     }
     /*
      * hydrate the result
      */
     $this->hydrateBrowser($result->getBrowser(), $browserRaw);
     // renderingEngine not available
     $this->hydrateOperatingSystem($result->getOperatingSystem(), $osRaw);
     $this->hydrateDevice($result->getDevice(), $osRaw, $deviceRaw);
     return $result;
 }
function hydrateResult(array $row2, \UserAgentParser\Model\UserAgent $result)
{
    $toHydrate = ['resBrowserName' => $result->getBrowser()->getName(), 'resBrowserVersion' => $result->getBrowser()->getVersion()->getComplete(), 'resEngineName' => $result->getRenderingEngine()->getName(), 'resEngineVersion' => $result->getRenderingEngine()->getVersion()->getComplete(), 'resOsName' => $result->getOperatingSystem()->getName(), 'resOsVersion' => $result->getOperatingSystem()->getVersion()->getComplete(), 'resDeviceModel' => $result->getDevice()->getModel(), 'resDeviceBrand' => $result->getDevice()->getBrand(), 'resDeviceType' => $result->getDevice()->getType(), 'resDeviceIsMobile' => $result->getDevice()->getIsMobile(), 'resDeviceIsTouch' => $result->getDevice()->getIsTouch(), 'resBotIsBot' => $result->getBot()->getIsBot(), 'resBotName' => $result->getBot()->getName(), 'resBotType' => $result->getBot()->getType(), 'resRawResult' => serialize($result->toArray(true)['providerResultRaw'])];
    return array_merge($row2, $toHydrate);
}
Exemplo n.º 13
0
 public function parse($userAgent, array $headers = [])
 {
     $parser = $this->getParser();
     $parser->analyze($userAgent);
     $browser = $parser->browser;
     $os = $parser->os;
     $device = $parser->device;
     $platform = $parser->platform;
     /*
      * No result found?
      */
     if ($this->hasResult($browser, $os, $device) !== true) {
         throw new NoResultFoundException('No result found for user agent: ' . $userAgent);
     }
     /*
      * Hydrate the model
      */
     $result = new Model\UserAgent();
     $result->setProviderResultRaw(['browser' => $browser, 'os' => $os, 'device' => $device, 'platform' => $platform]);
     /*
      * hydrate the result
      */
     $this->hydrateBrowser($result->getBrowser(), $browser);
     $this->hydrateOperatingSystem($result->getOperatingSystem(), $os);
     $this->hydrateDevice($result->getDevice(), $device);
     return $result;
 }
Exemplo n.º 14
0
 public function parse($userAgent, array $headers = [])
 {
     $headers['User-Agent'] = $userAgent;
     $parser = $this->getParser($headers);
     /*
      * No result found?
      */
     if ($parser->isDetected() !== true) {
         throw new Exception\NoResultFoundException('No result found for user agent: ' . $userAgent);
     }
     /*
      * Hydrate the model
      */
     $result = new Model\UserAgent();
     $result->setProviderResultRaw($parser->toArray());
     /*
      * Bot detection
      */
     if ($parser->getType() === 'bot') {
         $this->hydrateBot($result->getBot(), $parser->browser);
         return $result;
     }
     /*
      * hydrate the result
      */
     $this->hydrateBrowser($result->getBrowser(), $parser->browser);
     $this->hydrateRenderingEngine($result->getRenderingEngine(), $parser->engine);
     $this->hydrateOperatingSystem($result->getOperatingSystem(), $parser->os);
     $this->hydrateDevice($result->getDevice(), $parser->device, $parser);
     return $result;
 }
Exemplo n.º 15
0
 public function parse($userAgent, array $headers = [])
 {
     $parser = $this->getParser();
     $resultRaw = $parser->parse($userAgent);
     /*
      * No result found?
      */
     if ($this->hasResult($resultRaw) !== true) {
         throw new Exception\NoResultFoundException('No result found for user agent: ' . $userAgent);
     }
     /*
      * Hydrate the model
      */
     $result = new Model\UserAgent();
     $result->setProviderResultRaw($resultRaw);
     /*
      * Bot detection
      */
     if ($this->isBot($resultRaw) === true) {
         $this->hydrateBot($result->getBot(), $resultRaw);
         return $result;
     }
     /*
      * hydrate the result
      */
     $this->hydrateBrowser($result->getBrowser(), $resultRaw);
     // renderingEngine not available
     // operatingSystem filled OS is mixed! Examples: iPod, iPhone, Android...
     $this->hydrateDevice($result->getDevice(), $resultRaw);
     return $result;
 }
 public function parse($userAgent, array $headers = [])
 {
     $parser = $this->getParser();
     /* @var $resultRaw \UAParser\Result\Result */
     $resultRaw = $parser->parse($userAgent);
     /*
      * No result found?
      */
     if ($this->hasResult($resultRaw) !== true) {
         throw new Exception\NoResultFoundException('No result found for user agent: ' . $userAgent);
     }
     /* @var $emailRaw \UAParser\Result\EmailClientResult */
     // currently not used...any idea to implement it?
     /*
      * Hydrate the model
      */
     $result = new Model\UserAgent();
     $result->setProviderResultRaw($resultRaw);
     /*
      * Bot detection is currently not possible
      */
     /*
      * hydrate the result
      */
     $this->hydrateBrowser($result->getBrowser(), $resultRaw->getBrowser());
     $this->hydrateRenderingEngine($result->getRenderingEngine(), $resultRaw->getRenderingEngine());
     $this->hydrateOperatingSystem($result->getOperatingSystem(), $resultRaw->getOperatingSystem());
     $this->hydrateDevice($result->getDevice(), $resultRaw->getDevice());
     return $result;
 }