Example #1
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;
 }