-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdebug.php
74 lines (65 loc) · 2.28 KB
/
debug.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
<?php
/**
* Dump and die function. Outputs the information about a variable and terminates the execution of the script.
*
* @param mixed ...$args Variables to be dumped.
* @return void
*/
if (!function_exists('dd')) {
function dd() {
list($callee) = debug_backtrace();
$args = func_get_args();
echo '<style>.debugger{background: #fefefe; border:1px red solid; padding:15px;}.debugger legend{background:blue; color:white; padding:5px;}.debugger pre{white-space: pre-wrap;}</style>';
echo '<div class="debugger">';
echo '<legend>File: ' . htmlspecialchars($callee['file']) . ' @ line: ' . $callee['line'] . '</legend>';
ob_start();
foreach ($args as $arg) {
var_dump($arg);
}
$output = ob_get_clean();
echo '<pre>' . $output . '</pre>';
echo '</div>';
exit;
}
}
/**
* Debug to console function. Outputs the information about a variable to the browser's console.
*
* @param mixed ...$args Variables to be logged.
* @return void
* @throws Exception If headers are already sent and cannot output script tags.
*/
if (!function_exists('dc')) {
function dc() {
if (headers_sent()) {
throw new Exception('Headers already sent, cannot continue to print to console.');
}
$args = func_get_args();
foreach ($args as $arg) {
echo '<script>';
echo 'console.log(' . json_encode($arg) . ');';
echo '</script>';
}
}
}
/**
* Print readable function. Prints human-readable information about a variable.
*
* @param mixed ...$args Variables to be printed.
* @return void
*/
if (!function_exists('pr')) {
function pr() {
list($callee) = debug_backtrace();
$args = func_get_args();
echo '<style>.debugger{background: #fefefe; border:1px red solid; padding:15px;}.debugger legend{background:blue; color:white; padding:5px;}.debugger pre{white-space: pre-wrap;}</style>';
echo '<div class="debugger">';
echo '<legend>File: ' . htmlspecialchars($callee['file']) . ' @ line: ' . $callee['line'] . '</legend>';
foreach ($args as $arg) {
echo '<pre>';
print_r($arg);
echo '</pre>';
}
echo '</div>';
}
}