-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathDebug.php
85 lines (72 loc) · 1.49 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
75
76
77
78
79
80
81
82
83
84
85
<?php
namespace tourze\Base;
use Symfony\Component\VarDumper\VarDumper;
use Whoops\Handler\PrettyPageHandler;
use Whoops\Run;
/**
* 调试类的实现
*
* @package tourze\Base
*/
class Debug
{
/**
* @var Run
*/
protected static $_debugger = null;
/**
* @var bool 是否激活了内置的调试和错误处理方法
*/
public static $enabled = false;
/**
* @var array 需要显示出来的错误信息级别
*/
public static $shutdownErrors = [
E_PARSE,
E_ERROR,
E_USER_ERROR
];
/**
* @return \Whoops\Run
*/
public static function debugger()
{
return self::$_debugger;
}
/**
* 激活调试器
*/
public static function enable()
{
if (self::$enabled)
{
return;
}
self::$_debugger = new Run;
self::$_debugger->pushHandler(new PrettyPageHandler);
self::$_debugger->register();
self::$enabled = true;
}
/**
* 返回变量的打印html
*
* // 可以打印多个变量
* echo self::vars($foo, $bar, $baz);
*
* @return string
*/
public static function vars()
{
if (func_num_args() === 0)
{
return null;
}
$variables = func_get_args();
$output = [];
foreach ($variables as $var)
{
$output[] = VarDumper::dump($var);
}
return implode("\n", $output);
}
}