/** * Template method to apply matching system to user agent * * @param string $userAgent * @return string */ function applyMatch(WURFL_Request_GenericRequest $request) { $userAgent = $this->normalizeUserAgent($request->userAgent); $this->logger->debug("START: Matching For " . $userAgent); // Get The data associated with this current handler $this->userAgentsWithDeviceID = $this->persistenceProvider->load($this->getPrefix()); if (!is_array($this->userAgentsWithDeviceID)) { $this->userAgentsWithDeviceID = array(); } $deviceID = NULL; // we start with direct match if (array_key_exists($userAgent, $this->userAgentsWithDeviceID)) { return $this->userAgentsWithDeviceID[$userAgent]; } // Try with the conclusive Match $this->logger->debug("{$this->prefix} :Applying Conclusive Match for ua: {$userAgent}"); $deviceID = $this->applyConclusiveMatch($userAgent); if ($this->isBlankOrGeneric($deviceID)) { // Log the ua and the ua profile //$this->logger->debug ( $request ); $this->logger->debug("{$this->prefix} :Applying Recovery Match for ua: {$userAgent}"); $deviceID = $this->applyRecoveryMatch($userAgent); } // Try with catch all recovery Match if ($this->isBlankOrGeneric($deviceID)) { $this->logger->debug("{$this->prefix} :Applying Catch All Recovery Match for ua: {$userAgent}"); $deviceID = $this->applyRecoveryCatchAllMatch($userAgent); } if ($this->isBlankOrGeneric($deviceID)) { $deviceID = WURFL_Constants::GENERIC; } $this->logger->debug("END: Matching For " . $userAgent); return $deviceID; }
/** * Template method to apply matching system to user agent * * @param WURFL_Request_GenericRequest $request * @return string Device ID */ public function applyMatch(WURFL_Request_GenericRequest $request) { $class_name = get_class($this); $request->matchInfo->matcher = $class_name; $start_time = microtime(true); $request->matchInfo->cleaned_user_agent = $request->userAgentNormalized; $userAgent = $this->normalizeUserAgent($request->userAgentNormalized); $request->matchInfo->normalized_user_agent = $userAgent; $this->logger->debug("START: Matching For " . $userAgent); // Get The data associated with this current handler $this->userAgentsWithDeviceID = $this->persistenceProvider->load($this->getPrefix()); if (!is_array($this->userAgentsWithDeviceID)) { $this->userAgentsWithDeviceID = array(); } $deviceID = null; // Start with an Exact match $request->matchInfo->matcher_history .= "{$class_name}(exact),"; $request->matchInfo->match_type = 'exact'; $deviceID = $this->applyExactMatch($userAgent); // Try with the conclusive Match if ($this->isBlankOrGeneric($deviceID)) { $request->matchInfo->matcher_history .= "{$class_name}(conclusive),"; $this->logger->debug("{$this->prefix} :Applying Conclusive Match for ua: {$userAgent}"); $deviceID = $this->applyConclusiveMatch($userAgent); // Try with recovery match if ($this->isBlankOrGeneric($deviceID)) { // Log the ua and the ua profile //$this->logger->debug($request); $request->matchInfo->match_type = 'recovery'; $request->matchInfo->matcher_history .= "{$class_name}(recovery),"; $this->logger->debug("{$this->prefix} :Applying Recovery Match for ua: {$userAgent}"); $deviceID = $this->applyRecoveryMatch($userAgent); // Try with catch all recovery Match if ($this->isBlankOrGeneric($deviceID)) { $request->matchInfo->match_type = 'recovery-catchall'; $request->matchInfo->matcher_history .= "{$class_name}(recovery-catchall),"; $this->logger->debug("{$this->prefix} :Applying Catch All Recovery Match for ua: {$userAgent}"); $deviceID = $this->applyRecoveryCatchAllMatch($userAgent); // All attempts to match have failed if ($this->isBlankOrGeneric($deviceID)) { $request->matchInfo->match_type = 'none'; if ($request->userAgentProfile) { $deviceID = WURFL_Constants::GENERIC_MOBILE; } else { $deviceID = WURFL_Constants::GENERIC; } } } } } $this->logger->debug("END: Matching For " . $userAgent); $request->matchInfo->lookup_time = microtime(true) - $start_time; return $deviceID; }