UserAgentParser\Provider\SinergiBrowserDetector::parse PHP Method

parse() public method

public parse ( $userAgent, array $headers = [] )
$headers array
    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;
    }

Usage Example

 public function testRealResultDevice()
 {
     $provider = new SinergiBrowserDetector();
     $result = $provider->parse('Mozilla/5.0 (iPhone; CPU iPhone OS 5_0 like Mac OS X) AppleWebKit/534.46 (KHTML, like Gecko) Version/5.1 Mobile/9A334 Safari/7534.48.3');
     $this->assertEquals(['browser' => ['name' => 'Safari', 'version' => ['major' => 5, 'minor' => 1, 'patch' => null, 'alias' => null, 'complete' => '5.1']], 'renderingEngine' => ['name' => null, 'version' => ['major' => null, 'minor' => null, 'patch' => null, 'alias' => null, 'complete' => null]], 'operatingSystem' => ['name' => 'iOS', 'version' => ['major' => 5, 'minor' => 0, 'patch' => null, 'alias' => null, 'complete' => '5.0']], 'device' => ['model' => 'iPhone', 'brand' => null, 'type' => null, 'isMobile' => true, 'isTouch' => null], 'bot' => ['isBot' => null, 'name' => null, 'type' => null]], $result->toArray());
 }