/** * @param \Wurfl\Request\GenericRequest $request */ public function __construct(GenericRequest $request) { $this->httpRequest = $request; $this->deviceUa = $this->httpRequest->getDeviceUserAgent(); $this->browserUa = $this->httpRequest->getBrowserUserAgent(); $this->deviceUaNormalized = $this->httpRequest->getUserAgentNormalized(); $this->browserUaNormalized = $this->deviceUaNormalized; $this->browser = new NameVersionPair($this); $this->os = new NameVersionPair($this); }
/** * Adds the user agent hash and user agent to a list for retrieval in the demo (or for any reason i guess) * * @param \Wurfl\Request\GenericRequest $request * * @return \StdClass The core template object 'filled out' from ua-parser * @throws \BrowscapPHP\Exception */ private function createUAProperties(GenericRequest $request) { //$request->getDeviceUserAgent() . '||||' . $request->getBrowserUserAgent() $useragent = $request->getBrowserUserAgent(); $parser = Parser::create(); // classify the user agent string so we can learn more what device this really is. more for readability than anything /** @var \UAParser\Result\Client $client */ $client = $parser->parse($useragent); $obj = new \StdClass(); if ($request->getDeviceUserAgent() === $request->getBrowserUserAgent()) { $obj->originalUserAgent = $request->getBrowserUserAgent(); } else { $obj->originalUserAgent = new \StdClass(); $obj->originalUserAgent->browser = $request->getBrowserUserAgent(); $obj->originalUserAgent->device = $request->getDeviceUserAgent(); } // save properties from ua-parser $obj->uaparser = new \StdClass(); $obj->uaparser->ua = new \StdClass(); $obj->uaparser->ua->major = $client->ua->major; $obj->uaparser->ua->minor = $client->ua->minor; $obj->uaparser->ua->patch = $client->ua->patch; $obj->uaparser->ua->family = $client->ua->toString(); $obj->uaparser->os = new \StdClass(); $obj->uaparser->os->major = $client->os->major; $obj->uaparser->os->minor = $client->os->minor; $obj->uaparser->os->patch = $client->os->patch; $obj->uaparser->os->patchMinor = $client->os->patchMinor; $obj->uaparser->os->family = $client->os->toString(); $obj->uaparser->device = new \StdClass(); $obj->uaparser->device->brand = $client->device->brand; $obj->uaparser->device->model = $client->device->model; $obj->uaparser->device->family = $client->device->toString(); // Now, load an INI file into BrowscapPHP\Browscap for testing the UAs /* $browscap = new Browscap(); $browscap ->setCache($this->cache) ->setLogger($this->logger) ; $actualProps = (array) $browscap->getBrowser($useragent); $obj->browscap = new \StdClass(); foreach ($actualProps as $property => $value) { $obj->browscap->$property = $value; } /**/ return $obj; }