Source for file TeraWurflXMLParser_XMLReader_LowMem.php
Documentation is available at TeraWurflXMLParser_XMLReader_LowMem.php
* Tera_WURFL - PHP MySQL driven WURFL
* Tera-WURFL was written by Steve Kamerman, and is based on the
* Java WURFL Evolution package by Luca Passani and WURFL PHP Tools by Andrea Trassati.
* This version uses a MySQL database to store the entire WURFL file, multiple patch
* files, and a persistent caching mechanism to provide extreme performance increases.
* @package TeraWurflXMLParser
* @author Steve Kamerman <stevekamerman AT gmail.com>
* @version Stable 2.1.3 $Date: 2010/09/18 15:43:21
* @license http://www.mozilla.org/MPL/ MPL Vesion 1.1
* Loads the wurfl.xml file using the stream-based XMLReader class.
* This version is a HACK, made only for the purpose of extremely low
* memory usage, unlike the other XMLParsers, which are designed for
* speed of updating the database and sanity checking.
* @package TeraWurflXMLParser
private $pendingInsert = array();
throw new Exception("Cannot load XMLReader");
$this->dbcon = new mysqli(TeraWurflConfig::$DB_HOST,TeraWurflConfig::$DB_USER,TeraWurflConfig::$DB_PASS,TeraWurflConfig::$DB_SCHEMA);
$this->xml = new XMLReader();
public function open($filename,$file_type){
$this->xml->open($filename);
//TODO: add error handling
public function process(Array &$destination){
while($this->xml->read()){
switch ($this->xml->nodeType){
if($this->xml->name == "device"){
if($this->xml->name == "ver" || $this->xml->name == "last_updated"){
case XMLReader::END_ELEMENT:
return $this->xml->value;
if(count($this->pendingInsert)> 0){
foreach($this->pendingInsert as $device){
$this->pendingInsert = array();
$this->pendingInsert[$this->xml->getAttribute('id')] = array();
$device = & $this->pendingInsert[$this->xml->getAttribute('id')];
'id' => $this->xml->getAttribute('id'),
'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;
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){
$groupname = $this->xml->getAttribute('id');
if($filtering && $this->enabled($this->xml->getAttribute('id'))){
$device[$groupname] = array();
if(!$filtering || ($filtering && $includegroup)){
// the groupdevice array must already exist
$device[$groupname][$this->xml->getAttribute('name')] = self::cleanValue($this->xml->getAttribute('value'));
if($filtering && !$includegroup && $this->enabled($this->xml->getAttribute('name'))){
// the groupdevice array might already exists
$device[$groupname][$this->xml->getAttribute('name')] = self::cleanValue($this->xml->getAttribute('value'));
|