Data[] = Array('value' => $varValue, 'debug_type' => 'var_dump'); } } function prepareHTML($dataIndex) { $Data =& $this->Data[$dataIndex]; if($Data['debug_type'] == 'html') return $Data['html']; switch($Data['debug_type']) { case 'error': $fileLink = $this->getFileLink($Data['file'],$Data['line']); $ret = ''.$this->getErrorNameByCode($Data['no']).': '.$Data['str']; $ret .= ' in '.$fileLink.' on line '.$Data['line'].''; return $ret; break; case 'var_dump': $ret = highlight_string('', true); $ret = preg_replace('/<\?php (.*)\?>/s','$1',$ret); return addslashes($ret); break; case 'trace': $trace =& $Data['trace']; $i = 0; $traceCount = count($trace); $ret = ''; while($i < $traceCount) { $traceRec =& $trace[$i]; $argsID = 'trace_args_'.$dataIndex.'_'.$i; $ret .= 'Function: '.$this->getFileLink($traceRec['file'],$traceRec['line'],$traceRec['class'].$traceRec['type'].$traceRec['function']).''; $ret .= ' in '.basename($traceRec['file']).' on line '.$traceRec['line'].'
'; // ensure parameter value is not longer then 200 symbols $this->processTraceArguments($traceRec['args']); $args = $this->highlightString(print_r($traceRec['args'], true)); $ret .= ''; $i++; } return $ret; break; case 'profiler': $profileKey = $Data['profile_key']; $Data =& $this->ProfilerData[$profileKey]; $runtime = ($Data['ends'] - $Data['begins']); // in seconds return 'Name: '.$Data['description'].'
Runtime: '.$runtime.'s'; break; default: return 'incorrect debug data'; break; } } function processTraceArguments(&$traceArgs) { foreach ($traceRec['args'] as $argID => $argValue) { if( is_array($argValue) ) { $this->processTraceArguments($argValue); $traceRec['args'][$argID] = $argValue; } else { if( strlen($argValue) > 200 ) $traceRec['args'][$argID] = htmlspecialchars(substr($argValue,0,50).' ...'); } } } function highlightString($string) { $string = highlight_string('', true); return preg_replace('/<\?(.*)php (.*)\?>/s','$2',$string); } function getFileLink($file, $lineno = 1, $title = '') { if(!$title) $title = $file; return ''.$title.''; } function getLocalFile($remoteFile) { return str_replace(DOC_ROOT, WINDOWS_ROOT, $remoteFile); } function appendTrace() { $trace = debug_backtrace(); array_shift($trace); $this->Data[] = Array('trace' => $trace, 'debug_type' => 'trace'); } function appendHTML($html) { $this->Data[] = Array('html' => $html,'debug_type' => 'html'); } function profileStart($key, $description) { $timeStamp = $this->getMoment(); $this->ProfilerData[$key] = Array('begins' => $timeStamp, 'ends' => 5000, 'debuggerRowID' => count($this->Data), 'description' => $description); $this->Data[] = array('profile_key' => $key, 'debug_type' => 'profiler'); } function profileFinish($key) { $this->ProfilerData[$key]['ends'] = $this->getMoment(); } function getMoment() { list($usec, $sec) = explode(' ', microtime()); return ((float)$usec + (float)$sec); } function generateID() { list($usec, $sec) = explode(" ",microtime()); $id_part_1 = substr($usec, 4, 4); $id_part_2 = mt_rand(1,9); $id_part_3 = substr($sec, 6, 4); $digit_one = substr($id_part_1, 0, 1); if ($digit_one == 0) { $digit_one = mt_rand(1,9); $id_part_1 = ereg_replace("^0","",$id_part_1); $id_part_1=$digit_one.$id_part_1; } return $id_part_1.$id_part_2.$id_part_3; } function getErrorNameByCode($errorCode) { switch($errorCode) { case E_USER_ERROR: return 'Fatal Error'; break; case E_WARNING: case E_USER_WARNING: return 'Warning'; break; case E_NOTICE: case E_USER_NOTICE: return 'Notice'; break; default: return ''; break; } } /** * Generates report * */ function printReport() { $i = 0; $lineCount = count($this->Data); ?> error ['.$errno.'] = ['.$errstr.']
'; $errorType = $this->getErrorNameByCode($errno); if(!$errorType) { trigger_error('Unknown error type ['.$errno.']', E_USER_ERROR); return false; } $this->Data[] = Array('no' => $errno, 'str' => $errstr, 'file' => $errfile, 'line' => $errline, 'context' => $errcontext, 'debug_type' => 'error'); if( substr($errorType,0,5) == 'Fatal') { echo ''; exit; } } } $debugger = new Debugger(); $debugger->appendHTML('Hide Debugger'); set_error_handler( array(&$debugger,'saveError') ); register_shutdown_function( array(&$debugger,'printReport') ); ?>