Exemplo n.º 1
0
 protected function cacheLoad($objectId)
 {
     if ($this->cache === null) {
         return null;
     }
     return $this->cache->load('FCACHE_' . $objectId);
 }
 /**
  * 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;
     }
     $state = $this->persistenceStorage->load(self::WURFL_API_STATE);
     return !$this->isStateCurrent($state);
 }
Exemplo n.º 3
0
 /**
  * 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;
 }
Exemplo n.º 4
0
 /**
  * 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;
 }
 /**
  * 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;
 }
Exemplo n.º 6
0
 private function verifyRepository()
 {
     /**
      * verify required device ids
      */
     foreach ($this->userAgentHandlerChain->getHandlers() as $handler) {
         /**
          * @var $handler WURFL_Handlers_Handler
          */
         foreach ($handler::$constantIDs as $require_device_id) {
             $device = $this->persistenceProvider->load($require_device_id);
             if ($device === null) {
                 throw new WURFL_Exception_WURFLConsistencyException("wurfl.xml load error - you may need to update the wurfl.xml file to a more recent version");
             }
         }
     }
     /**
      * verify required capabilities
      */
     $required_caps = WURFL_VirtualCapabilityProvider::getRequiredCapabilities();
     $generic_device = new WURFL_CustomDevice([$this->persistenceProvider->load('generic')]);
     $loaded_caps = array_keys($generic_device->getAllCapabilities());
     $missing_caps = array_diff($required_caps, $loaded_caps);
     if (count($missing_caps) > 0) {
         throw new WURFL_Exception_WURFLConsistencyException("Missing required WURFL Capabilities: " . implode(', ', $missing_caps));
     }
     $invalid_fallbacks = array_diff(array_keys($this->fallbacks), $this->devices);
     if (count($invalid_fallbacks) > 0) {
         foreach ($invalid_fallbacks as $invalid_fallback) {
             $device = new WURFL_CustomDevice([$this->persistenceProvider->load($this->fallbacks[$invalid_fallback])]);
             throw new WURFL_Exception_WURFLConsistencyException(sprintf("Invalid Fallback %s for the device %s", $invalid_fallback, $device->id));
         }
     }
     unset($this->fallbacks);
     unset($this->devices);
 }