/** * 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; }
/** * Returns true if the WURFL is out of date or otherwise needs to be reloaded * @return bool */ public function hasToBeReloaded() { if (!$this->wurflConfig->allowReload) { return false; } $lastModificationTime = $this->persistenceStorage->load(self::WURFL_LAST_MODIFICATION_TIME); $currentModificationTime = filemtime($this->wurflConfig->wurflFile); return $currentModificationTime > $lastModificationTime; }
/** * 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"); } // TODO: Prevent infinite recursion while (strcmp($deviceId, "root")) { $device = $this->persistenceProvider->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; }