コード例 #1
0
 public function testConstruct()
 {
     $userAgent = 'testUA';
     $header = array(Constants::HEADER_HTTP_USERAGENT => $userAgent);
     $object = new GenericRequest($header, $userAgent, null, false);
     self::assertSame($userAgent, $object->getUserAgent());
     self::assertSame($userAgent, $object->getUserAgentNormalized());
     self::assertSame($header, $object->getRequest());
     self::assertFalse($object->isXhtmlDevice());
     self::assertNull($object->getUserAgentProfile());
     self::assertSame(hash('sha512', $userAgent), $object->getId());
     self::assertInstanceOf('\\Wurfl\\Request\\MatchInfo', $object->getMatchInfo());
     self::assertSame(array(), $object->getUserAgentsWithDeviceID());
     self::assertSame($userAgent, $object->getOriginalHeader(Constants::HEADER_HTTP_USERAGENT));
     self::assertNull($object->getOriginalHeader(Constants::HEADER_DEVICE_STOCK_UA));
 }
コード例 #2
0
ファイル: Manager.php プロジェクト: mimmi20/wurfl
 /**
  * Returns the device id for the device that matches the $request
  *
  * @param \Wurfl\Request\GenericRequest $request WURFL Request object
  *
  * @return string WURFL device id
  */
 private function deviceIdForRequest(Request\GenericRequest $request)
 {
     $userAgent = $request->getUserAgent();
     if (!$userAgent) {
         // $request->id is not set
         // -> do not try to get info from cache nor try to save to the cache
         $request->getMatchInfo()->fromCache = 'invalid id';
         $request->getMatchInfo()->lookupTime = 0.0;
         return $this->getUserAgentHandlerChain()->match($request);
     }
     $deviceId = $this->getCacheStorage()->load($userAgent);
     if (empty($deviceId)) {
         $genericNormalizer = UserAgentHandlerChainFactory::createGenericNormalizers();
         $request->setUserAgentNormalized($genericNormalizer->normalize($userAgent));
         if ($this->getWurflConfig()->isHighPerformance() && Handlers\Utils::isDesktopBrowserHeavyDutyAnalysis($request->getUserAgentNormalized())) {
             // This device has been identified as a web browser programatically,
             // so no call to WURFL is necessary
             $deviceId = WurflConstants::GENERIC_WEB_BROWSER;
         } else {
             $deviceId = $this->getUserAgentHandlerChain()->match($request);
         }
         // save it in cache
         $this->getCacheStorage()->save($userAgent, $deviceId);
     } else {
         $request->getMatchInfo()->fromCache = true;
         $request->getMatchInfo()->lookupTime = 0.0;
     }
     return $deviceId;
 }