sourcemod/tools/profiler/php/ProfFileParser.class.php
Scott Ehlert 251cced1f8 Spring Cleaning, Part Ichi (1)
Various minor things done to project files
Updated sample extension project file and updated makefile to the new unified version (more changes likely on the way)
Updated regex project file and makefile

--HG--
extra : convert_revision : svn%3A39bc706e-5318-0410-9160-8a85361fbb7c/trunk%401971
2008-03-30 07:00:22 +00:00

74 lines
1.3 KiB
PHP

<?php
class ProfReport
{
public $time;
public $uptime;
public $items = array();
}
class ProfReportParser
{
private $report;
private $curtype;
public $last_error;
public function Parse($file)
{
$this->report = FALSE;
$this->curtype = FALSE;
if (($contents = file_get_contents($file)) === FALSE)
{
$this->last_error = 'File not found';
return FALSE;
}
$xml = xml_parser_create();
xml_set_object($xml, $this);
xml_set_element_handler($xml, 'tag_open', 'tag_close');
xml_parser_set_option($xml, XML_OPTION_CASE_FOLDING, false);
if (!xml_parse($xml, $contents))
{
$this->last_error = 'Line: ' . xml_get_current_line_number($xml) . ' -- ' . xml_error_string(xml_get_error_code($xml));
return FALSE;
}
return $this->report;
}
public function tag_open($parser, $tag, $attrs)
{
if ($tag == 'profile')
{
$this->report = new ProfReport();
$this->report->time = $attrs['time'];
$this->report->uptime = $attrs['uptime'];
}
else if ($tag == 'report')
{
$this->curtype = $attrs['name'];
}
else if ($tag == 'item')
{
if ($this->report === FALSE || $this->curtype === FALSE)
{
return;
}
$attrs['type'] = $this->curtype;
$this->report->items[] = $attrs;
}
}
public function tag_close($parser, $tag)
{
if ($tag == 'report')
{
$this->curtype = FALSE;
}
}
}
?>