/** * Return a Cabability Value * * @param string $deviceID * @param string $capabilityName * @return string */ public function getCapabilityForDevice($deviceID, $capabilityName) { $key = $deviceID . $capabilityName; $capabilityValue = $this->_cacheProvider->get($key); if (empty($capabilityValue)) { $capabilityValue = $this->_deviceRepository->getCapabilityForDevice($deviceID, $capabilityName); // save it in cache $this->_cacheProvider->put($key, $capabilityValue); } return $capabilityValue; }
protected function cacheClear() { if ($this->cache === null) { return; } $this->cache->clear(); }
/** * 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; }
/** * Save given $device in the persistence provider. This is called when loading the WURFL XML * data, directly after reading the complete device node. * @param WURFL_Xml_ModelDevice $device * @see WURFL_UserAgentHandlerChain::filter(), WURFL_Storage_Base::save() */ private function classifyAndPersistDevice($device) { if ($this->validateDevice($device) === false) { return; } array_push($this->devices, $device->id); if ($device->fallBack != 'root') { $this->fallbacks[$device->fallBack] = $device->id; } $this->userAgentHandlerChain->filter($device->userAgent, $device->id); $this->persistenceProvider->save($device->id, $device); }
/** * Returns the value for the given $deviceId and $capabilityName * * @param string $deviceId * @param string $capabilityName * @throws WURFL_WURFLException device ID or capability was not found * @return string value */ public function getCapabilityForDevice($deviceId, $capabilityName) { if (!$this->isCapabilityDefined($capabilityName)) { throw new WURFL_WURFLException("capability name: " . $capabilityName . " not found"); } $capabilityValue = null; // TODO: Prevent infinite recursion while (strcmp($deviceId, "root")) { $device = $this->persistenceStorage->load($deviceId); if (!$device) { throw new WURFL_WURFLException("the device with {$deviceId} is not found."); } if (isset($device->capabilities[$capabilityName])) { $capabilityValue = $device->capabilities[$capabilityName]; break; } $deviceId = $device->fallBack; } return $capabilityValue; }
/** * Save given $device in the persistence provider. This is called when loading the WURFL XML * data, directly after reading the complete device node. * @param WURFL_Xml_ModelDevice $device * @see WURFL_UserAgentHandlerChain::filter(), WURFL_Storage_Base::save() */ private function classifyAndPersistDevice($device) { $this->userAgentHandlerChain->filter($device->userAgent, $device->id); $this->persistenceProvider->save($device->id, $device); }
/** * Clears the data in the persistence provider * @see WURFL_Storage_Base::clear() */ public function remove() { $this->persistenceStorage->clear(); $this->wurflManager = null; }