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));
 }
 /**
  * Returns the match info for this device
  *
  * @return \Wurfl\Request\MatchInfo|null
  */
 public function getMatchInfo()
 {
     return $this->request instanceof Request\GenericRequest ? $this->request->getMatchInfo() : null;
 }
Beispiel #3
0
 /**
  * Template method to apply matching system to user agent
  *
  * @param \Wurfl\Request\GenericRequest $request
  *
  * @return string Device ID
  */
 public final function applyMatch(GenericRequest $request)
 {
     $className = get_class($this);
     $request->getMatchInfo()->matcher = $className;
     $startTime = microtime(true);
     $request->getMatchInfo()->cleanedUserAgent = $request->getUserAgentNormalized();
     $userAgent = $this->normalizeUserAgent($request->getUserAgentNormalized());
     $request->getMatchInfo()->normalizedUserAgent = $userAgent;
     $this->logger->debug('START: Matching For ' . $userAgent);
     // Get The data associated with this current handler
     $this->userAgentsWithDeviceID = $this->getUserAgentsWithDeviceId();
     $this->userAgents = $this->getUserAgentsForBucket();
     $matches = array('exact' => array('history' => '(exact),', 'function' => 'applyExactMatch', 'debug' => 'Applying Exact Match'), 'conclusive' => array('history' => '(conclusive),', 'function' => 'applyConclusiveMatch', 'debug' => 'Applying Conclusive Match'), 'recovery' => array('history' => '(recovery),', 'function' => 'applyRecoveryMatch', 'debug' => 'Applying Recovery Match'), 'recovery-catchall' => array('history' => '(recovery-catchall),', 'function' => 'applyRecoveryCatchAllMatch', 'debug' => 'Applying Catch All Recovery Match'));
     $deviceID = WurflConstants::NO_MATCH;
     foreach ($matches as $matchType => $matchProps) {
         $matchProps = (object) $matchProps;
         $request->getMatchInfo()->matcherHistory .= $className . $matchProps->history;
         $request->getMatchInfo()->matchType = $matchType;
         $request->setUserAgentsWithDeviceID($this->userAgentsWithDeviceID);
         $this->logger->debug($this->prefix . ' :' . $matchProps->debug . ' for ua: ' . $userAgent);
         $function = $matchProps->function;
         $deviceID = $this->{$function}($userAgent);
         if (!$this->isBlankOrGeneric($deviceID)) {
             break;
         }
     }
     // All attempts to match have failed
     if ($this->isBlankOrGeneric($deviceID)) {
         $request->getMatchInfo()->matchType = 'none';
         if ($request->getUserAgentProfile()) {
             $deviceID = WurflConstants::GENERIC_MOBILE;
         } else {
             $deviceID = WurflConstants::GENERIC;
         }
     }
     $this->logger->debug('END: Matching For ' . $userAgent);
     $request->getMatchInfo()->lookupTime = microtime(true) - $startTime;
     return $deviceID;
 }
Beispiel #4
0
 /**
  * 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;
 }