2007-10-15 02:43:29 +04:00
|
|
|
<?php
|
|
|
|
/*
|
|
|
|
* $Id$
|
|
|
|
*
|
|
|
|
* Copyright(c) 2004-2006, SpikeSource Inc. All Rights Reserved.
|
|
|
|
* Licensed under the Open Software License version 2.1
|
|
|
|
* (See http://www.spikesource.com/license.html)
|
|
|
|
*/
|
|
|
|
?>
|
|
|
|
<?php
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Reader that parses Xdebug Trace data.
|
|
|
|
*
|
|
|
|
* @author Nimish Pachapurkar <npac@spikesource.com>
|
|
|
|
* @version $Revision: $
|
|
|
|
* @package SpikePHPCoverage_Parser
|
|
|
|
*/
|
|
|
|
class XdebugTraceReader {
|
|
|
|
/*{{{ Members */
|
|
|
|
|
|
|
|
protected $traceFilePath;
|
|
|
|
protected $handle;
|
|
|
|
protected $coverage = array();
|
|
|
|
|
|
|
|
/*}}}*/
|
|
|
|
/*{{{ Constructor */
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Constructor
|
|
|
|
*
|
|
|
|
* @param $traceFilePath Path of the Xdebug trace file
|
|
|
|
* @access public
|
|
|
|
*/
|
|
|
|
public function __construct($traceFilePath) {
|
|
|
|
$this->traceFilePath = $traceFilePath;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*}}}*/
|
|
|
|
/*{{{ protected function openTraceFile() */
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Opens the trace file
|
|
|
|
*
|
|
|
|
* @return Boolean True on success, false on failure.
|
|
|
|
* @access protected
|
|
|
|
*/
|
|
|
|
protected function openTraceFile() {
|
|
|
|
$this->handle = fopen($this->traceFilePath, "r");
|
|
|
|
return !empty($this->handle);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*}}}*/
|
|
|
|
/*{{{ public function parseTraceFile() */
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Parses the trace file
|
|
|
|
*
|
|
|
|
* @return Boolean True on success, false on failure.
|
|
|
|
* @access public
|
|
|
|
*/
|
|
|
|
public function parseTraceFile() {
|
2007-10-21 10:23:59 +04:00
|
|
|
if( ! $this->openTraceFile()) {
|
2007-10-15 02:43:29 +04:00
|
|
|
error_log("[XdebugTraceReader::parseTraceFile()] Unable to read trace file.");
|
|
|
|
return false;
|
|
|
|
}
|
2007-10-21 10:23:59 +04:00
|
|
|
while( ! feof($this->handle)) {
|
2007-10-15 02:43:29 +04:00
|
|
|
$line = fgets($this->handle);
|
|
|
|
// echo "Line: " . $line . "\n";
|
|
|
|
$this->processTraceLine($line);
|
|
|
|
}
|
|
|
|
fclose($this->handle);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*}}}*/
|
|
|
|
/*{{{ protected function processTraceLine() */
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Process a give trace line
|
|
|
|
*
|
|
|
|
* @param $line Line from a trace file
|
|
|
|
* @return Boolean True on success, false on failure
|
|
|
|
* @access protected
|
|
|
|
*/
|
|
|
|
protected function processTraceLine($line) {
|
|
|
|
$dataparts = explode("\t", $line);
|
|
|
|
// print_r($dataparts);
|
|
|
|
$cnt = count($dataparts);
|
|
|
|
if($cnt < 2) {
|
|
|
|
return false;
|
|
|
|
}
|
2007-10-21 10:23:59 +04:00
|
|
|
if( ! file_exists($dataparts[$cnt-2])) {
|
2007-10-15 02:43:29 +04:00
|
|
|
// echo "No file: " . $dataparts[$cnt-2] . "\n";
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
// Trim the entries
|
|
|
|
$dataparts[$cnt-2] = trim($dataparts[$cnt-2]);
|
|
|
|
$dataparts[$cnt-1] = trim($dataparts[$cnt-1]);
|
|
|
|
|
2007-10-21 10:23:59 +04:00
|
|
|
if( ! isset($this->coverage[$dataparts[$cnt-2]][$dataparts[$cnt-1]])) {
|
2007-10-15 02:43:29 +04:00
|
|
|
$this->coverage[$dataparts[$cnt-2]][$dataparts[$cnt-1]] = 1;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
$this->coverage[$dataparts[$cnt-2]][$dataparts[$cnt-1]] ++;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*}}}*/
|
|
|
|
/*{{{ public function getCoverageData() */
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns the coverage array
|
|
|
|
*
|
|
|
|
* @return Array Array of coverage data from parsing.
|
|
|
|
* @access public
|
|
|
|
*/
|
|
|
|
public function getCoverageData() {
|
|
|
|
return $this->coverage;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*}}}*/
|
|
|
|
}
|
|
|
|
?>
|