Example #1
0
 /**
  * Constructor.
  *
  * @param string $userAgent  HTTP user agent string
  * @param string $httpAccept HTTP accept header
  */
 public function __construct($userAgent = null, $httpAccept = null)
 {
     // Don't call parent::__construct as it attempts to connect the DB
     // every time (we want it rather static) - following is other stuff
     // from there:
     $this->errors = array();
     $this->capabilities = array();
     $this->matcherHistory = array();
     $this->rootdir = dirname(__FILE__) . '/';
     // Create the database connection only once
     // @see Tx_ContextsWurfl_Api_Wurfl_DatabaseConnector::connect()
     if (!self::$staticDb) {
         $db = new Tx_ContextsWurfl_Api_Wurfl_DatabaseConnector();
         if (!$db->connect()) {
             throw new TeraWurflDatabaseException('Cannot connect to database: ' . $db->getLastError());
         }
         self::$staticDb = $db;
     }
     $this->db = self::$staticDb;
     try {
         // Get device capabilities
         $this->getDeviceCapabilitiesFromAgent($userAgent, $httpAccept);
     } catch (Exception $e) {
         //no nothing here.
         // we show errors in the context wurfl configuration
     }
 }
Example #2
0
 /**
  * Perform match by product infos.
  *
  * @return Tx_ContextsWurfl_Context_Type_Wurfl
  */
 protected function matchProductInfo()
 {
     // Brand names
     $brandNames = $this->getConfValue('settings.brandName', null, 'sProductInfo');
     if (strlen($brandNames)) {
         $brandNames = explode(',', $brandNames);
         $brandMatch = false;
         foreach ($brandNames as $brandName) {
             $brandMatch |= strcasecmp($brandName, $this->wurfl->getBrandName()) === 0;
         }
         $this->match &= $brandMatch;
     }
     // Model names
     $modelNames = $this->getConfValue('settings.modelName', null, 'sProductInfo');
     if (strlen($modelNames)) {
         $modelNames = explode(',', $modelNames);
         $modelMatch = false;
         foreach ($modelNames as $modelName) {
             $modelMatch |= strcasecmp($modelName, $this->wurfl->getModelName()) === 0;
         }
         $this->match &= $modelMatch;
     }
     // Mobile browsers
     $mobileBrowsers = $this->getConfValue('settings.mobileBrowser', null, 'sProductInfo');
     if (strlen($mobileBrowsers)) {
         $mobileBrowsers = explode(',', $mobileBrowsers);
         $mobileMatch = false;
         foreach ($mobileBrowsers as $mobileBrowser) {
             $mobileMatch |= strcasecmp($mobileBrowser, $this->wurfl->getMobileBrowser()) === 0;
         }
         $this->match &= $mobileMatch;
     }
     return $this;
 }