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;
}
/** * Device only */ public function testParseDeviceDefaultValue() { $parseResult = new stdClass(); $parseResult->user_agent = 'A real user agent...'; $parseResult->operating_platform = 'Android Phone'; $parseResult->operating_platform_vendor_name = 'Dell'; $rawResult = new stdClass(); $rawResult->result = 'success'; $rawResult->parse = $parseResult; $responseQueue = [new Response(200, ['Content-Type' => 'application/json'], json_encode($rawResult))]; $provider = new WhatIsMyBrowserCom($this->getClient($responseQueue), 'apiKey123'); $result = $provider->parse('A real user agent...'); $expectedResult = ['device' => ['model' => null, 'brand' => 'Dell', 'type' => null, 'isMobile' => null, 'isTouch' => null]]; $this->assertProviderResult($result, $expectedResult); }