roykin/tools/antadis_tools/debug/AntDebugger.php

80 lines
2.4 KiB
PHP

<?php
if (!class_exists('AntDebugger')) {
class AntDebugger
{
static function backtrace($show_args = false, $output_html = true)
{
static $nb_times = 0;
$newline = PHP_EOL;
if ($output_html) {
$newline = '<br />';
}
if ($show_args) {
$result = debug_backtrace();
}
else {
$result = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS);
}
$results = array();
foreach ($result as $index => $rows) {
if ((isset($rows['class']) && $rows['class'] != 'AntDebugger') || $rows['function'] != 'backtrace') {
$res = '';
if (isset($rows['class'])) {
$res .= $rows['class'].'::';
}
$file = $rows['file'];
if (isset($_SERVER['CONTEXT_DOCUMENT_ROOT'])) {
$file = str_replace($_SERVER['CONTEXT_DOCUMENT_ROOT'], '', $file);
}
$res = $res.$rows['function'].'() --- ['.$file.':'.$rows['line'].']';
if ($show_args && isset($rows['args'])) {
$res .= ' with args : ';
if ($output_html) {
$res .= "<pre style='margin-top:0px;padding-left:60px'>";
}
$res .= print_r($rows['args'], true);
if ($output_html) {
$res .= "</pre>";
}
}
$results[] = $res;
}
}
krsort($results, SORT_NUMERIC);
if ($output_html) {
echo "<div style='background-color:white;'>";
}
$level = 0;
foreach ($results as $trace) {
$padding = str_pad('', $level*3, '-', STR_PAD_LEFT);
if ($level > 0) {
$padding = $padding.' ';
}
echo "#".$level." ".$padding.$trace.$newline;
$level++;
}
$nb_times++;
echo "Nb times : ".$nb_times;
echo $newline;
echo $newline;
if ($output_html) {
echo "</div>";
}
}
}
}