UserAgentParser\Provider\Endorphin::parse PHP Method

parse() public method

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

Usage Example

 public function testRealResultDevice()
 {
     $provider = new Endorphin();
     $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' => 7534, 'minor' => 48, 'patch' => 3, 'alias' => null, 'complete' => '7534.48.3']], 'renderingEngine' => ['name' => null, 'version' => ['major' => null, 'minor' => null, 'patch' => null, 'alias' => null, 'complete' => null]], 'operatingSystem' => ['name' => 'Mac OS X', 'version' => ['major' => null, 'minor' => null, 'patch' => null, 'alias' => null, 'complete' => null]], 'device' => ['model' => null, 'brand' => null, 'type' => 'mobile', 'isMobile' => null, 'isTouch' => null], 'bot' => ['isBot' => null, 'name' => null, 'type' => null]], $result->toArray());
 }