UserAgentParser\Provider\Http\NeutrinoApiCom::parse PHP Method

parse() public method

public parse ( $userAgent, array $headers = [] )
$headers array
    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->hydrateOperatingSystem($result->getOperatingSystem(), $resultRaw);
        $this->hydrateDevice($result->getDevice(), $resultRaw);
        return $result;
    }

Usage Example

 /**
  * Device - default value
  */
 public function testParseDeviceDefaultValue()
 {
     $rawResult = new stdClass();
     $rawResult->type = 'mobile-browser';
     $rawResult->mobile_model = 'Android';
     $rawResult->mobile_brand = 'Generic';
     $responseQueue = [new Response(200, ['Content-Type' => 'application/json;charset=UTF-8'], json_encode($rawResult))];
     $provider = new NeutrinoApiCom($this->getClient($responseQueue), 'apiUser', 'apiKey123');
     $result = $provider->parse('A real user agent...');
     $expectedResult = ['device' => ['model' => null, 'brand' => null, 'type' => 'mobile-browser', 'isMobile' => null, 'isTouch' => null]];
     $this->assertProviderResult($result, $expectedResult);
 }
All Usage Examples Of UserAgentParser\Provider\Http\NeutrinoApiCom::parse