Skip to content

Commit 17a6b35

Browse files
committed
Improved Debugger output
1 parent cb0b56d commit 17a6b35

File tree

1 file changed

+52
-27
lines changed

1 file changed

+52
-27
lines changed

src/Debugger.php

Lines changed: 52 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -8,19 +8,24 @@
88
*/
99
class Debugger {
1010
/**
11-
* @var bool
11+
* @var string|null
1212
*/
13-
public static $output = true;
13+
public static $documentRoot = null;
1414

1515
/**
1616
* @var bool
1717
*/
1818
public static $showCalledFrom = true;
1919

2020
/**
21-
* @var string|null
21+
* @var bool
2222
*/
23-
public static $documentRoot = null;
23+
public static $output = true;
24+
25+
/**
26+
* @var bool
27+
*/
28+
private static $outputStyles = true;
2429

2530
/**
2631
* @param string $data
@@ -33,31 +38,48 @@ public static function output($data) {
3338
}
3439

3540
if (php_sapi_name() == 'cli') {
36-
$data = (self::$showCalledFrom ? self::getCalledFrom(2) . "\n" . $data : $data);
37-
38-
echo '#################### DEBUG ####################';
41+
echo '######################### DEBUG #########################';
3942
echo "\n";
43+
if (self::$showCalledFrom) {
44+
echo self::getCalledFrom(2);
45+
echo "\n";
46+
}
4047
echo $data;
4148
echo "\n";
4249
} else {
43-
$data = (self::$showCalledFrom ? '<strong>' . self::getCalledFrom(2) . '</strong>' . "\n" . $data : $data);
44-
45-
$style = [];
46-
$style[] = 'margin:5px 0;';
47-
$style[] = 'padding:5px;';
48-
$style[] = 'font-family:Consolas,Courier New,​monospace;';
49-
$style[] = 'font-weight:normal;';
50-
$style[] = 'font-size:13px;';
51-
$style[] = 'line-height:1.2;';
52-
$style[] = 'color:#555;';
53-
$style[] = 'background:#F9F9F9;';
54-
$style[] = 'border:1px solid #CCC;';
55-
$style[] = 'display:block;';
56-
$style[] = 'overflow:auto;';
57-
58-
echo '<pre style="' . implode(' ', $style) . '">';
50+
echo '<pre class="xicrow-php-debug-debugger">';
51+
if (self::$showCalledFrom) {
52+
echo '<div class="xicrow-php-debug-debugger__called-from">';
53+
echo self::getCalledFrom(2);
54+
echo '</div>';
55+
}
5956
echo $data;
6057
echo '</pre>';
58+
if (self::$outputStyles) {
59+
echo '<style type="text/css">';
60+
echo 'pre.xicrow-php-debug-debugger{';
61+
echo 'margin:5px 0;';
62+
echo 'padding:5px;';
63+
echo 'font-family:Consolas,Courier New,​monospace;';
64+
echo 'font-weight:normal;';
65+
echo 'font-size:13px;';
66+
echo 'line-height:1.2;';
67+
echo 'color:#555;';
68+
echo 'background:#FFF;';
69+
echo 'border:1px solid #CCC;';
70+
echo 'display:block;';
71+
echo 'overflow:auto;';
72+
echo '}';
73+
echo 'pre.xicrow-php-debug-debugger div.xicrow-php-debug-debugger__called-from{';
74+
echo 'margin: 0 0 5px 0;';
75+
echo 'padding: 0 0 5px 0;';
76+
echo 'border-bottom: 1px solid #CCC;';
77+
echo 'font-style: italic;';
78+
echo '}';
79+
echo '</style>';
80+
81+
self::$outputStyles = false;
82+
}
6183
}
6284
}
6385

@@ -260,11 +282,14 @@ public static function getCalledFromTrace($trace) {
260282
$calledFromFunction .= $trace['function'] . '()';
261283
}
262284

263-
if (!empty($calledFromFunction) && !empty($calledFromFile)) {
264-
$calledFromFunction = ' > ' . $calledFromFunction;
285+
// Return called from
286+
if ($calledFromFile) {
287+
return $calledFromFile;
288+
} elseif ($calledFromFunction) {
289+
return $calledFromFunction;
290+
} else {
291+
return 'Unable to get called from trace';
265292
}
266-
267-
return $calledFromFile . $calledFromFunction;
268293
}
269294

270295
/**

0 commit comments

Comments
 (0)