/**
  * Returns a CacheProvider based on the given $cacheConfig
  * @param WURFL_Configuration_Config $cacheConfig 
  * @return WURFL_Cache_CacheProvider
  */
 public static function getCacheProvider($cacheConfig = null)
 {
     $cacheConfig = is_null($cacheConfig) ? WURFL_Configuration_ConfigHolder::getWURFLConfig()->cache : $cacheConfig;
     $provider = isset($cacheConfig["provider"]) ? $cacheConfig["provider"] : NULL;
     $cache = isset($cacheConfig["params"]) ? $cacheConfig["params"] : NULL;
     switch ($provider) {
         case WURFL_Constants::FILE:
             self::$_cacheProvider = new WURFL_Cache_FileCacheProvider($cache);
             break;
         case WURFL_Constants::MEMCACHE:
             self::$_cacheProvider = new WURFL_Cache_MemcacheCacheProvider($cache);
             break;
         case WURFL_Constants::APC:
             self::$_cacheProvider = new WURFL_Cache_APCCacheProvider($cache);
             break;
         case WURFL_Constants::EACCELERATOR:
             self::$_cacheProvider = new WURFL_Cache_EAcceleratorCacheProvider($cache);
             break;
         case WURFL_Constants::MYSQL:
             self::$_cacheProvider = new WURFL_Cache_MysqlCacheProvider($cache);
             break;
         default:
             self::$_cacheProvider = new WURFL_Cache_NullCacheProvider();
             break;
     }
     return self::$_cacheProvider;
 }
Esempio n. 2
0
 public function applyConclusiveMatch($userAgent)
 {
     $matches = array();
     if (preg_match('/^Mozilla\\/4\\.0 \\(compatible; MSIE (\\d)\\.(\\d);/', $userAgent, $matches)) {
         if (WURFL_Configuration_ConfigHolder::getWURFLConfig()->isHighPerformance()) {
             return WURFL_Constants::GENERIC_WEB_BROWSER;
         }
         switch ($matches[1]) {
             // cases are intentionally out of sequence for performance
             case 7:
                 return 'msie_7';
                 break;
             case 8:
                 return 'msie_8';
                 break;
             case 9:
                 return 'msie_9';
                 break;
             case 6:
                 return 'msie_6';
                 break;
             case 4:
                 return 'msie_4';
                 break;
             case 5:
                 return $matches[2] == 5 ? 'msie_5_5' : 'msie_5';
                 break;
             default:
                 return 'msie';
                 break;
         }
     }
     $tolerance = WURFL_Handlers_Utils::firstSlash($userAgent);
     return $this->getDeviceIDFromRIS($userAgent, $tolerance);
 }
Esempio n. 3
0
 /**
  * Returns A CacheProvider
  *
  * @return CacheProvider
  */
 public static function getCacheProvider()
 {
     $cache = WURFL_Configuration_ConfigHolder::getWURFLConfig()->cache;
     $provider = $cache["provider"];
     switch ($provider) {
         case WURFL_Constants::FILE:
             self::$_cacheProvider = new WURFL_Cache_FileCacheProvider($cache);
             break;
         case WURFL_Constants::MEMCACHE:
             self::$_cacheProvider = new WURFL_Cache_MemcacheCacheProvider($cache);
             break;
         case WURFL_Constants::APC:
             self::$_cacheProvider = new WURFL_Cache_APCCacheProvider($cache);
             break;
         case WURFL_Constants::EACCELERATOR:
             self::$_cacheProvider = new WURFL_Cache_EAcceleratorCacheProvider($cache);
             break;
         case WURFL_Constants::MYSQL:
             self::$_cacheProvider = new WURFL_Cache_MysqlCacheProvider($cache);
             break;
         default:
             self::$_cacheProvider = new WURFL_Cache_NullCacheProvider();
             break;
     }
     return self::$_cacheProvider;
 }
Esempio n. 4
0
 /**
  * Initializes the XMLResourcesManager
  *
  * @param WURFL_Xml_PersistenceProvider $persistenceProvider
  * @param WURFL_Xml_PatchManager $patchManager
  * @param WURFL_Xml_WURFLFileParser $wurflParser
  * @param WURFL_Xml_WURFLPatchFileParser $wurflPatchParser
  */
 function __construct(WURFL_Xml_PersistenceProvider $persistenceProvider, WURFL_Xml_PatchManager $patchManager, WURFL_Xml_WURFLFileParser $wurflParser, WURFL_Xml_WURFLPatchFileParser $wurflPatchParser)
 {
     $this->_config = WURFL_Configuration_ConfigHolder::getWURFLConfig();
     $this->_patchManager = $patchManager;
     $this->_wurflParser = $wurflParser;
     $this->_wurflPatchParser = $wurflPatchParser;
     $this->_persistenceProvider = $persistenceProvider;
     $this->init();
 }
 /**
  * If UA starts with Mozilla, apply LD with tolerance 5.
  *
  * @param string $userAgent
  * @return string
  */
 public function applyConclusiveMatch($userAgent)
 {
     if (WURFL_Configuration_ConfigHolder::getWURFLConfig()->isHighPerformance()) {
         //High performance mode
         $tolerance = WURFL_Handlers_Utils::firstCloseParen($userAgent) + 1;
         return $this->getDeviceIDFromRIS($userAgent, $tolerance);
     } else {
         //High accuracy mode
         return $this->getDeviceIDFromLD($userAgent, 5);
     }
 }
 private static function _initialize()
 {
     $persistenceParams = WURFL_Configuration_ConfigHolder::getWURFLConfig()->persistence;
     $provider = $persistenceParams["provider"];
     switch ($provider) {
         case WURFL_Constants::MEMCACHE:
             self::$_persistenceProvider = new WURFL_Xml_PersistenceProvider_MemcachePersistenceProvider($persistenceParams);
             break;
         case WURFL_Constants::APC:
             self::$_persistenceProvider = new WURFL_Xml_PersistenceProvider_APCPersistenceProvider($persistenceParams);
             break;
         case WURFL_Constants::MYSQL:
             self::$_persistenceProvider = new WURFL_Xml_PersistenceProvider_MysqlPersistenceProvider($persistenceParams);
             break;
         default:
             self::$_persistenceProvider = new WURFL_Xml_PersistenceProvider_FilePersistenceProvider($persistenceParams);
             break;
     }
 }
 /**
  * Initializes the Persistence Provider Manager
  * @param array $persistenceConfig Persistence configuration
  * @see WURFL_Configuration_ConfigHolder::getWURFLConfig()
  */
 private static function _initialize($persistenceConfig)
 {
     $persistenceConfig = is_null($persistenceConfig) ? WURFL_Configuration_ConfigHolder::getWURFLConfig()->persistence : $persistenceConfig;
     $provider = $persistenceConfig["provider"];
     $persistenceParams = isset($persistenceConfig["params"]) ? $persistenceConfig["params"] : array();
     switch ($provider) {
         case WURFL_Constants::MEMCACHE:
             self::$_persistenceProvider = new WURFL_Xml_PersistenceProvider_MemcachePersistenceProvider($persistenceParams);
             break;
         case WURFL_Constants::APC:
             self::$_persistenceProvider = new WURFL_Xml_PersistenceProvider_APCPersistenceProvider($persistenceParams);
             break;
         case WURFL_Constants::MYSQL:
             self::$_persistenceProvider = new WURFL_Xml_PersistenceProvider_MysqlPersistenceProvider($persistenceParams);
             break;
         case WURFL_Xml_PersistenceProvider_InMemoryPersistenceProvider::IN_MEMORY:
             self::$_persistenceProvider = new WURFL_Xml_PersistenceProvider_InMemoryPersistenceProvider($persistenceParams);
             break;
         default:
             self::$_persistenceProvider = new WURFL_Xml_PersistenceProvider_FilePersistenceProvider($persistenceParams);
             break;
     }
 }
Esempio n. 8
0
 public function run(WURFL_WURFLManager $wurflManager)
 {
     $this->failure_count = 0;
     // Verify API Version
     if ($this->min_version && version_compare(WURFL_Constants::API_VERSION, $this->min_version, '<')) {
         throw new CentralTest_InvalidIntrospectorVersionException("Test requires WURFL PHP API >= {$this->min_version} (current " . WURFL_Constants::API_VERSION . ")");
     }
     // Verify correct mode
     if ($this->mode != self::MODE_ALL) {
         $required_mode = $this->mode == self::MODE_HIGH_PERFORMANCE ? WURFL_Configuration_Config::MATCH_MODE_PERFORMANCE : WURFL_Configuration_Config::MATCH_MODE_ACCURACY;
         WURFL_Configuration_ConfigHolder::getWURFLConfig()->matchMode($required_mode);
     }
     $request_factory = new WURFL_Request_GenericRequestFactory();
     $request = $request_factory->createRequest($this->http_headers, $this->ua_override);
     $device = $wurflManager->getDeviceForRequest($request);
     foreach ($this->assertions as $assertion) {
         /* @var $assertion CentralTestAssertion */
         $assertion->wurflManager = $wurflManager;
         if (!$assertion->assert($device)) {
             $this->failure_count++;
         }
     }
     return $this->failure_count === 0;
 }
Esempio n. 9
0
 /**
  * Return a device the given WURFL_Request_GenericRequest request(user-agent..)
  *
  * @param WURFL_Request_GenericRequest $request
  * @return WURFL_CustomDevice device
  * @throws Exception if the $request parameter is not set
  */
 public function getDeviceForRequest(WURFL_Request_GenericRequest $request)
 {
     if (!isset($request)) {
         throw new Exception("The request parameter must be set.");
     }
     WURFL_Handlers_Utils::reset();
     if (WURFL_Configuration_ConfigHolder::getWURFLConfig()->isHighPerformance() && WURFL_Handlers_Utils::isDesktopBrowserHeavyDutyAnalysis($request->userAgent)) {
         // This device has been identified as a web browser programatically, so no call to WURFL is necessary
         return $this->_wurflService->getDevice(WURFL_Constants::GENERIC_WEB_BROWSER);
     }
     return $this->_wurflService->getDeviceForRequest($request);
 }
Esempio n. 10
0
 /**
  * Returns the device id for the device that matches the $request
  * @param WURFL_Request_GenericRequest $request WURFL Request object
  * @return string WURFL device id
  */
 private function deviceIdForRequest($request)
 {
     $deviceId = $this->_cacheProvider->load($request->id);
     if (empty($deviceId)) {
         $generic_normalizer = WURFL_UserAgentHandlerChainFactory::createGenericNormalizers();
         $request->userAgentNormalized = $generic_normalizer->normalize($request->userAgent);
         if (WURFL_Configuration_ConfigHolder::getWURFLConfig()->isHighPerformance() && WURFL_Handlers_Utils::isDesktopBrowserHeavyDutyAnalysis($request->userAgentNormalized)) {
             // This device has been identified as a web browser programatically, so no call to WURFL is necessary
             return WURFL_Constants::GENERIC_WEB_BROWSER;
         }
         $deviceId = $this->_userAgentHandlerChain->match($request);
         // save it in cache
         $this->_cacheProvider->save($request->id, $deviceId);
     } else {
         $request->matchInfo->from_cache = true;
         $request->matchInfo->lookup_time = 0.0;
     }
     return $deviceId;
 }
Esempio n. 11
0
 protected function actionInfo()
 {
     $info = $this->wurfl->getWURFLInfo();
     $config = WURFL_Configuration_ConfigHolder::getWURFLConfig();
     $this->response['info'] = array('api' => 'PHP API', 'api_version' => WURFL_Constants::API_VERSION, 'mode' => 'high-' . $config->matchMode, 'wurfl_version' => $info->version, 'loaded_patches' => is_array($config->wurflPatches) ? implode(',', $config->wurflPatches) : '', 'platform' => 'PHP ' . PHP_VERSION, 'app_server' => $_SERVER['SERVER_SOFTWARE'], 'os' => php_uname());
     $this->response['success'] = true;
     $this->sendResponse();
 }
Esempio n. 12
0
 private static function isLoggingConfigured()
 {
     $wurflConfig = WURFL_Configuration_ConfigHolder::getWURFLConfig();
     $logDir = $wurflConfig->logDir;
     return isset($wurflConfig->logDir) && is_writable($logDir);
 }