|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
class Kint_Parser_Trace extends Kint_Parser_Plugin |
|
|
|
|
|
|
4
|
|
|
{ |
|
5
|
|
|
public static $blacklist = array('spl_autoload_call'); |
|
6
|
|
|
|
|
7
|
|
|
public function getTypes() |
|
8
|
|
|
{ |
|
9
|
|
|
return array('array'); |
|
10
|
|
|
} |
|
11
|
|
|
|
|
12
|
|
|
public function getTriggers() |
|
|
|
|
|
|
13
|
|
|
{ |
|
14
|
|
|
return Kint_Parser::TRIGGER_SUCCESS; |
|
15
|
|
|
} |
|
16
|
|
|
|
|
17
|
|
|
public function parse(&$var, Kint_Object &$o, $trigger) |
|
|
|
|
|
|
18
|
|
|
{ |
|
19
|
|
|
if (!$o->value) { |
|
20
|
|
|
return; |
|
21
|
|
|
} |
|
22
|
|
|
|
|
23
|
|
|
$trace = $this->parser->getCleanArray($var); |
|
24
|
|
|
|
|
25
|
|
|
if (count($trace) !== count($o->value->contents) || !self::isTrace($trace)) { |
|
26
|
|
|
return; |
|
27
|
|
|
} |
|
28
|
|
|
|
|
29
|
|
|
$o = $o->transplant(new Kint_Object_Trace()); |
|
30
|
|
|
$rep = $o->value; |
|
31
|
|
|
|
|
32
|
|
|
$old_trace = $rep->contents; |
|
|
|
|
|
|
33
|
|
|
|
|
34
|
|
|
self::normalizeAliases(self::$blacklist); |
|
35
|
|
|
|
|
36
|
|
|
$rep->contents = array(); |
|
37
|
|
|
|
|
38
|
|
|
foreach ($old_trace as $frame) { |
|
|
|
|
|
|
39
|
|
|
$index = $frame->name; |
|
40
|
|
|
|
|
41
|
|
|
if (!isset($trace[$index]['function'])) { |
|
42
|
|
|
// Something's very very wrong here, but it's probably a plugin's fault |
|
43
|
|
|
continue; |
|
44
|
|
|
} |
|
45
|
|
|
|
|
46
|
|
|
if (self::frameIsListed($trace[$index], self::$blacklist)) { |
|
47
|
|
|
continue; |
|
48
|
|
|
} |
|
49
|
|
|
|
|
50
|
|
|
$rep->contents[$index] = $frame->transplant(new Kint_Object_TraceFrame()); |
|
51
|
|
|
$rep->contents[$index]->assignFrame($trace[$index]); |
|
52
|
|
|
} |
|
53
|
|
|
|
|
54
|
|
|
ksort($rep->contents); |
|
55
|
|
|
$rep->contents = array_values($rep->contents); |
|
56
|
|
|
|
|
57
|
|
|
$o->clearRepresentations(); |
|
58
|
|
|
$o->addRepresentation($rep); |
|
59
|
|
|
$o->size = count($rep->contents); |
|
60
|
|
|
} |
|
61
|
|
|
|
|
62
|
|
|
public static function isTrace(array $trace) |
|
63
|
|
|
{ |
|
64
|
|
|
if (!Kint_Object::isSequential($trace)) { |
|
65
|
|
|
return false; |
|
66
|
|
|
} |
|
67
|
|
|
|
|
68
|
|
|
static $bt_structure = array( |
|
69
|
|
|
'function' => 'string', |
|
70
|
|
|
'line' => 'integer', |
|
71
|
|
|
'file' => 'string', |
|
72
|
|
|
'class' => 'string', |
|
73
|
|
|
'object' => 'object', |
|
74
|
|
|
'type' => 'string', |
|
75
|
|
|
'args' => 'array', |
|
76
|
|
|
); |
|
77
|
|
|
|
|
78
|
|
|
$file_found = false; |
|
|
|
|
|
|
79
|
|
|
|
|
80
|
|
|
foreach ($trace as $frame) { |
|
81
|
|
|
if (!is_array($frame) || !isset($frame['function'])) { |
|
82
|
|
|
return false; |
|
83
|
|
|
} |
|
84
|
|
|
|
|
85
|
|
|
foreach ($frame as $key => $val) { |
|
86
|
|
|
if (!isset($bt_structure[$key])) { |
|
|
|
|
|
|
87
|
|
|
return false; |
|
88
|
|
|
} elseif (gettype($val) !== $bt_structure[$key]) { |
|
|
|
|
|
|
89
|
|
|
return false; |
|
90
|
|
|
} elseif ($key === 'file') { |
|
91
|
|
|
$file_found = true; |
|
|
|
|
|
|
92
|
|
|
} |
|
93
|
|
|
} |
|
94
|
|
|
} |
|
95
|
|
|
|
|
96
|
|
|
return $file_found; |
|
|
|
|
|
|
97
|
|
|
} |
|
98
|
|
|
|
|
99
|
|
|
public static function frameIsListed(array $frame, array $matches) |
|
|
|
|
|
|
100
|
|
|
{ |
|
101
|
|
|
if (isset($frame['class'])) { |
|
102
|
|
|
$called = array(strtolower($frame['class']), strtolower($frame['function'])); |
|
103
|
|
|
} else { |
|
104
|
|
|
$called = strtolower($frame['function']); |
|
105
|
|
|
} |
|
106
|
|
|
|
|
107
|
|
|
return in_array($called, $matches, true); |
|
108
|
|
|
} |
|
109
|
|
|
|
|
110
|
|
|
public static function normalizeAliases(array &$aliases) |
|
111
|
|
|
{ |
|
112
|
|
|
foreach ($aliases as $index => &$alias) { |
|
113
|
|
|
if (is_array($alias) && count($alias) === 2) { |
|
114
|
|
|
$alias = array_values(array_filter($alias, 'is_string')); |
|
115
|
|
|
|
|
116
|
|
|
if (count($alias) === 2 && |
|
117
|
|
|
preg_match('/^[a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]*$/', $alias[1]) && |
|
118
|
|
|
preg_match('/^[a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff\\\\]*$/', $alias[0]) |
|
119
|
|
|
) { |
|
120
|
|
|
$alias = array( |
|
121
|
|
|
strtolower(ltrim($alias[0], '\\')), |
|
122
|
|
|
strtolower($alias[1]), |
|
123
|
|
|
); |
|
124
|
|
|
} else { |
|
125
|
|
|
unset($aliases[$index]); |
|
126
|
|
|
continue; |
|
127
|
|
|
} |
|
128
|
|
|
} elseif (is_string($alias)) { |
|
129
|
|
|
if (preg_match('/^[a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]*$/', $alias)) { |
|
130
|
|
|
$alias = strtolower($alias); |
|
131
|
|
|
} else { |
|
132
|
|
|
unset($aliases[$index]); |
|
133
|
|
|
continue; |
|
134
|
|
|
} |
|
135
|
|
|
} else { |
|
136
|
|
|
unset($aliases[$index]); |
|
137
|
|
|
} |
|
138
|
|
|
} |
|
139
|
|
|
|
|
140
|
|
|
$aliases = array_values($aliases); |
|
141
|
|
|
} |
|
142
|
|
|
} |
|
143
|
|
|
|
This check examines a number of code elements and verifies that they conform to the given naming conventions.
You can set conventions for local variables, abstract classes, utility classes, constant, properties, methods, parameters, interfaces, classes, exceptions and special methods.