protected function parseDevice() { if (count($this->pendingInsert) > 0) { foreach ($this->pendingInsert as $device) { $matcher = UserAgentFactory::userAgentType($this->wurfl, $device['user_agent']); $uatable = TeraWurflConfig::$TABLE_PREFIX . '_' . $matcher; } $this->pendingInsert = array(); } $this->pendingInsert[$this->xml->getAttribute('id')] = array(); $device =& $this->pendingInsert[$this->xml->getAttribute('id')]; $device = array('id' => $this->xml->getAttribute('id'), 'user_agent' => UserAgentUtils::cleanUserAgent($this->xml->getAttribute('user_agent')), 'fall_back' => $this->xml->getAttribute('fall_back')); if ($this->xml->getAttribute('actual_device_root')) { $device['actual_device_root'] = $this->xml->getAttribute('actual_device_root') == "true" ? 1 : 0; } $groupdevice = ''; $groupname = ''; $filtering = TeraWurflConfig::$CAPABILITY_FILTER ? true : false; $includegroup = false; while ($this->xml->read()) { if ($this->xml->nodeType != XMLReader::ELEMENT) { continue; } // recurse back into this function for the rest of the devices switch ($this->xml->name) { case "device": $this->parseDevice(); break; case "group": $groupname = $this->xml->getAttribute('id'); if ($filtering && $this->enabled($this->xml->getAttribute('id'))) { $includegroup = true; } else { $includegroup = false; continue; } $device[$groupname] = array(); break; case "capability": if (!$filtering || $filtering && $includegroup) { // the groupdevice array must already exist $device[$groupname][$this->xml->getAttribute('name')] = self::cleanValue($this->xml->getAttribute('value')); continue; } if ($filtering && !$includegroup && $this->enabled($this->xml->getAttribute('name'))) { // the groupdevice array might already exists if (!array_key_exists($groupname, $device)) { $device[$groupname] = array(); } $device[$groupname][$this->xml->getAttribute('name')] = self::cleanValue($this->xml->getAttribute('value')); continue; } break; } } }
/** * Sorts the validated data from $this->devices into their respective UserAgentMatcher tables ($this->tables) * based on the UserAgentMatcher that matches the device's user agent * @return Bool Success */ public function sort() { $this->timesort = microtime(true); foreach ($this->devices as $id => &$device) { // This will return something like "Nokia", "Motorola", or "CatchAll" $matcher = UserAgentFactory::userAgentType($this->wurfl, $device['user_agent']); // TeraWurfl_Nokia $uatable = $this->table . '_' . $matcher; if (!isset($this->tables[$uatable])) { $this->tables[$uatable] = array(); } $this->tables[$uatable][$device['id']] = $device; } // Destroy the devices array $this->devices = array(); return true; }