Exemple #1
0
 /**
  * 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 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;
 }
 /**
  * Clears the data in the persistence provider
  * @see WURFL_Xml_PersistenceProvider::clear()
  */
 public function remove()
 {
     $this->persistenceStorage->clear();
     $this->wurflManager = null;
 }
 /**
  * Save given $device in the persistence provider
  * @param WURFL_Device $device
  * @see WURFL_UserAgentHandlerChain::filter(), WURFL_Xml_PersistenceProvider::save()
  */
 private function classifyAndPersistDevice($device)
 {
     $this->userAgentHandlerChain->filter($device->userAgent, $device->id);
     $this->persistenceProvider->save($device->id, $device);
 }