/**
  * @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);
 }
 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));
 }
Example #3
0
 /**
  * Return the the device id for the request
  *
  * @param \Wurfl\Request\GenericRequest $request
  *
  * @return string deviceID
  */
 public function match(GenericRequest $request)
 {
     Utils::reset();
     $handlers = $this->getHandlers();
     $matchResult = WurflConstants::NO_MATCH;
     foreach ($handlers as $handler) {
         /** @var $handler \Wurfl\Handlers\AbstractHandler */
         $handler->setLogger($this->logger);
         if ($handler->canHandle($request->getUserAgentNormalized())) {
             $matchResult = $handler->applyMatch($request);
             break;
         }
     }
     return $matchResult;
 }
Example #4
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;
 }