tools/profiler/php/ProfFileParser.class.php
author Ruben Gonzalez <drifter01620@gmail.com>
Thu May 22 09:49:27 2014 -0400 (2014-05-22)
changeset 4378 568f4497ef4a
parent 1908 318e0a01aef9
permissions -rw-r--r--
Update CS:GO team score gamedata.
     1 <?php
     2 
     3 class ProfReport
     4 {
     5 	public $time;
     6 	public $uptime;
     7 	public $items = array();
     8 }
     9 
    10 class ProfReportParser
    11 {
    12 	private $report;
    13 	private $curtype;
    14 	public $last_error;
    15 
    16 	public function Parse($file)
    17 	{
    18 		$this->report = FALSE;
    19 		$this->curtype = FALSE;
    20 
    21 		if (($contents = file_get_contents($file)) === FALSE)
    22 		{
    23 			$this->last_error = 'File not found';
    24 			return FALSE;
    25 		}
    26 		
    27 		$xml = xml_parser_create();
    28 		xml_set_object($xml, $this);
    29 		xml_set_element_handler($xml, 'tag_open', 'tag_close');
    30 		xml_parser_set_option($xml, XML_OPTION_CASE_FOLDING, false);
    31 
    32 		if (!xml_parse($xml, $contents))
    33 		{
    34 			$this->last_error = 'Line: ' . xml_get_current_line_number($xml) . ' -- ' . xml_error_string(xml_get_error_code($xml));
    35 			return FALSE;
    36 		}
    37 
    38 		return $this->report;
    39 	}
    40 
    41 	public function tag_open($parser, $tag, $attrs)
    42 	{
    43 		if ($tag == 'profile')
    44 		{
    45 			$this->report = new ProfReport();
    46 			$this->report->time = $attrs['time'];
    47 			$this->report->uptime = $attrs['uptime'];
    48 		}
    49 		else if ($tag == 'report')
    50 		{
    51 			$this->curtype = $attrs['name'];
    52 		}
    53 		else if ($tag == 'item')
    54 		{
    55 			if ($this->report === FALSE || $this->curtype === FALSE)
    56 			{
    57 				return;
    58 			}
    59 			$attrs['type'] = $this->curtype;
    60 			$this->report->items[] = $attrs;
    61 		}
    62 	}
    63 
    64 	public function tag_close($parser, $tag)
    65 	{
    66 		if ($tag == 'report')
    67 		{
    68 			$this->curtype = FALSE;
    69 		}
    70 	}
    71 }
    72 
    73 ?>