Moodle  2.2.1
http://www.collinsharper.com
C:/xampp/htdocs/moodle/lib/spikephpcoverage/src/remote/XdebugTraceReader.php
Go to the documentation of this file.
00001 <?php
00002     /*
00003     *  $Id: XdebugTraceReader.php,v 1.2 2010/12/14 17:36:05 moodlerobot Exp $
00004     *  
00005     *  Copyright(c) 2004-2006, SpikeSource Inc. All Rights Reserved.
00006     *  Licensed under the Open Software License version 2.1
00007     *  (See http://www.spikesource.com/license.html)
00008     */
00009 ?>
00010 <?php
00011 
00019     class XdebugTraceReader {
00020         /*{{{ Members */
00021 
00022         protected $traceFilePath;
00023         protected $handle;
00024         protected $coverage = array();
00025 
00026         /*}}}*/
00027         /*{{{ Constructor */
00028 
00035         public function __construct($traceFilePath) {
00036             $this->traceFilePath = $traceFilePath;
00037         }
00038 
00039         /*}}}*/
00040         /*{{{ protected function openTraceFile() */
00041 
00048         protected function openTraceFile() {
00049             $this->handle = fopen($this->traceFilePath, "r");
00050             return !empty($this->handle);
00051         }
00052 
00053         /*}}}*/
00054         /*{{{ public function parseTraceFile() */
00055 
00062         public function parseTraceFile() {
00063             if(!$this->openTraceFile()) {
00064                 error_log("[XdebugTraceReader::parseTraceFile()] Unable to read trace file.");
00065                 return false;
00066             }
00067             while(!feof($this->handle)) {
00068                 $line = fgets($this->handle);
00069                 // echo "Line: " . $line . "\n";
00070                 $this->processTraceLine($line);
00071             }
00072             fclose($this->handle);
00073             return true;
00074         }
00075 
00076         /*}}}*/
00077         /*{{{ protected function processTraceLine() */
00078 
00086         protected function processTraceLine($line) {
00087             $dataparts = explode("\t", $line);
00088             // print_r($dataparts);
00089             $cnt = count($dataparts);
00090             if($cnt < 2) {
00091                 return false;
00092             }
00093             if(!file_exists($dataparts[$cnt-2])) {
00094                 // echo "No file: " . $dataparts[$cnt-2] . "\n";
00095                 return false;
00096             }
00097             // Trim the entries
00098             $dataparts[$cnt-2] = trim($dataparts[$cnt-2]);
00099             $dataparts[$cnt-1] = trim($dataparts[$cnt-1]);
00100 
00101             if(!isset($this->coverage[$dataparts[$cnt-2]][$dataparts[$cnt-1]])) {
00102                 $this->coverage[$dataparts[$cnt-2]][$dataparts[$cnt-1]] = 1;
00103             }
00104             else {
00105                 $this->coverage[$dataparts[$cnt-2]][$dataparts[$cnt-1]] ++;
00106             }
00107             return true;
00108         }
00109 
00110         /*}}}*/
00111         /*{{{ public function getCoverageData() */
00112 
00119         public function getCoverageData() {
00120             return $this->coverage;
00121         }
00122 
00123         /*}}}*/
00124     }
00125 ?>
 All Data Structures Namespaces Files Functions Variables Enumerations