-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathDumper.php
113 lines (98 loc) · 4.84 KB
/
Dumper.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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
<?php
namespace sb\prettydumper;
class Dumper
{
public static $style_block = 'font-size: 11px; border: 1px dashed #ddd; padding: 5px; margin: 2px; text-align: left; background-color: #f9f9f9;';
public static $style_boolean = 'color: #FF0000;';
public static $style_integer = 'color: #0000FF;';
public static $style_float = 'color: #660099;';
public static $style_callable = 'color: #999900;';
public static $style_string = 'color: #009900;';
public static $style_array = 'color: #660000;';
public static $style_object = 'color: #003399;';
public static $style_resource = 'color: #DD66FF;';
public static $style_null = 'color: #000000;';
public static $style_unknown = 'color: #000000;';
public static $style_key = 'color: #ce7b00;';
private static $onclick = "var s1=document.getElementById('error_close_%s').style; var s2=document.getElementById('error_open_%s').style; s1.display=s1.display=='none'?'block':'none'; s2.display=s2.display=='none'?'block':'none';";
protected static $plugins = array('sb\prettydumper\DumperArray', 'sb\prettydumper\DumperObject', 'sb\prettydumper\DumperImage');
public static function getStyle($style)
{
return strlen($style) ? ' style="' . $style . '"' : '';
}
public static function varDumpExtend($arg, $tab = 0)
{
if (count(self::$plugins))
{
foreach (self::$plugins as $plugin)
{
if (call_user_func(array($plugin, 'is'), $arg))
{
return call_user_func(array($plugin, 'format'), $arg, $tab);
}
}
}
return self::varDump($arg)."\n";
}
public static function varDump($arg)
{
switch (true)
{
case is_bool($arg):
$param = $arg == true ? "true" : "false";
$type = '<span'.self::getStyle(self::$style_boolean).'>boolean</span>';
break;
case is_int($arg):
$param = strval($arg);
$type = '<span'.self::getStyle(self::$style_integer).'>integer</span>';
break;
case is_float($arg):
$param = strval($arg);
$type = '<span'.self::getStyle(self::$style_float).'>float</span>';
break;
case is_string($arg):
$param = '"'.htmlspecialchars($arg).'"';
$param = preg_replace("/\r\n/", "\\r\\n", $param);
$param = preg_replace("/\n/", "\\n", $param);
$param = preg_replace("/\r/", "\\r", $param);
$param = preg_replace("/\t/", "\\t", $param);
$type = '<span'.self::getStyle(self::$style_string).'>string['.strlen($arg).']</span>';
break;
case is_array($arg):
$param = print_r($arg, true);
$param = preg_replace("/\\r\\n/", " ", $param);
$param = preg_replace("/\\n/", " ", $param);
$param = preg_replace("/\\t/", " ", $param);
$param = preg_replace("'\\s+'i", " ", $param);
$param = htmlspecialchars($param);
$type = '<span'.self::getStyle(self::$style_array).'>array['.count($arg).']</span>';
break;
case is_object($arg):
$param = print_r($arg, 1);
$param = preg_replace("/\\r\\n/", " ", $param);
$param = preg_replace("/\\n/", " ", $param);
$param = preg_replace("/\\t/", " ", $param);
$param = preg_replace("'\\s+'i", " ", $param);
$param = htmlspecialchars($param);
$type = '<span'.self::getStyle(self::$style_object).'>object['.get_class($arg).']</span>';
break;
case is_resource($arg):
$param = '"' . get_resource_type($arg) . '"';
$type = '<span'.self::getStyle(self::$style_resource).'>resource</span>';
break;
case is_null($arg):
$param = '';
$type = '<span'.self::getStyle(self::$style_null).'>null</span>';
break;
default:
$param = '';
$type = '<span'.self::getStyle(self::$style_boolean).'>unknown</span>';
break;
}
return $type.' '.$param.'';
}
public static function Dump($arg)
{
return '<pre'.self::getStyle(self::$style_block).'>'.self::varDumpExtend($arg).'</pre>';
}
}