|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
class Kint_Parser_ClassStatics extends Kint_Parser_Plugin |
|
4
|
|
|
{ |
|
5
|
|
|
private static $cache = array(); |
|
6
|
|
|
|
|
7
|
|
|
public function getTypes() |
|
8
|
|
|
{ |
|
9
|
|
|
return array('object'); |
|
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
|
|
|
$class = get_class($var); |
|
20
|
|
|
$reflection = new ReflectionClass($class); |
|
21
|
|
|
|
|
22
|
|
|
// Constants |
|
23
|
|
|
// TODO: PHP 7.1 allows private consts but reflection doesn't have a way to check them yet |
|
24
|
|
|
if (!isset(self::$cache[$class])) { |
|
25
|
|
|
$consts = array(); |
|
26
|
|
|
|
|
27
|
|
|
foreach ($reflection->getConstants() as $name => $val) { |
|
28
|
|
|
$const = Kint_Object::blank($name); |
|
29
|
|
|
$const->const = true; |
|
30
|
|
|
$const->depth = $o->depth + 1; |
|
31
|
|
|
$const->owner_class = $class; |
|
32
|
|
View Code Duplication |
if (KINT_PHP53) { |
|
33
|
|
|
$const->access_path = '\\'.$class.'::'.$const->name; |
|
34
|
|
|
} else { |
|
35
|
|
|
$const->access_path = $class.'::'.$const->name; |
|
36
|
|
|
} |
|
37
|
|
|
$const->operator = Kint_Object::OPERATOR_STATIC; |
|
38
|
|
|
$const = $this->parser->parse($val, $const); |
|
39
|
|
|
|
|
40
|
|
|
$consts[] = $const; |
|
41
|
|
|
} |
|
42
|
|
|
|
|
43
|
|
|
self::$cache[$class] = $consts; |
|
44
|
|
|
} |
|
45
|
|
|
|
|
46
|
|
|
$statics = new Kint_Object_Representation('Static class properties', 'statics'); |
|
47
|
|
|
$statics->contents = self::$cache[$class]; |
|
48
|
|
|
|
|
49
|
|
|
// Statics |
|
50
|
|
|
|
|
51
|
|
|
if (!KINT_PHP53) { |
|
52
|
|
|
$static_map = $reflection->getStaticProperties(); |
|
53
|
|
|
} |
|
54
|
|
|
|
|
55
|
|
|
foreach ($reflection->getProperties(ReflectionProperty::IS_STATIC) as $static) { |
|
56
|
|
|
$prop = new Kint_Object(); |
|
57
|
|
|
$prop->name = '$'.$static->getName(); |
|
58
|
|
|
$prop->depth = $o->depth + 1; |
|
59
|
|
|
$prop->static = true; |
|
60
|
|
|
$prop->operator = Kint_Object::OPERATOR_STATIC; |
|
61
|
|
|
|
|
62
|
|
|
if (KINT_PHP53) { |
|
63
|
|
|
$prop->owner_class = $static->getDeclaringClass()->name; |
|
64
|
|
|
} else { |
|
65
|
|
|
// getDeclaringClass() is broke in old PHP versions, but getProperties() will only |
|
66
|
|
|
// return accessible properties and we can access them through the parent class so |
|
67
|
|
|
// we can just put the parent class here. It's not an accurate portrayal of where |
|
68
|
|
|
// the static comes from, but it shows a working access path so it's good enough |
|
69
|
|
|
$prop->owner_class = $class; |
|
70
|
|
|
} |
|
71
|
|
|
|
|
72
|
|
|
$prop->access = Kint_Object::ACCESS_PUBLIC; |
|
73
|
|
View Code Duplication |
if ($static->isProtected()) { |
|
74
|
|
|
$prop->access = Kint_Object::ACCESS_PROTECTED; |
|
75
|
|
|
} elseif ($static->isPrivate()) { |
|
76
|
|
|
$prop->access = Kint_Object::ACCESS_PRIVATE; |
|
77
|
|
|
} |
|
78
|
|
|
|
|
79
|
|
|
if ($this->parser->childHasPath($o, $prop)) { |
|
|
|
|
|
|
80
|
|
View Code Duplication |
if (KINT_PHP53) { |
|
81
|
|
|
$prop->access_path = '\\'.$prop->owner_class.'::'.$prop->name; |
|
82
|
|
|
} else { |
|
83
|
|
|
$prop->access_path = $prop->owner_class.'::'.$prop->name; |
|
84
|
|
|
} |
|
85
|
|
|
} |
|
86
|
|
|
|
|
87
|
|
|
if (KINT_PHP53) { |
|
88
|
|
|
$static->setAccessible(true); |
|
89
|
|
|
$val = $static->getValue(); |
|
90
|
|
|
} else { |
|
91
|
|
|
switch ($prop->access) { |
|
92
|
|
|
case Kint_Object::ACCESS_PUBLIC: |
|
93
|
|
|
$val = $static_map[$static->getName()]; |
|
|
|
|
|
|
94
|
|
|
break; |
|
95
|
|
|
case Kint_Object::ACCESS_PROTECTED: |
|
96
|
|
|
$val = $static_map["\0*\0".$static->getName()]; |
|
97
|
|
|
break; |
|
98
|
|
|
case Kint_Object::ACCESS_PRIVATE: |
|
99
|
|
|
$val = $static_map["\0".$class."\0".$static->getName()]; |
|
100
|
|
|
break; |
|
101
|
|
|
} |
|
102
|
|
|
} |
|
103
|
|
|
|
|
104
|
|
|
$statics->contents[] = $this->parser->parse($val, $prop); |
|
105
|
|
|
} |
|
106
|
|
|
|
|
107
|
|
|
if (empty($statics->contents)) { |
|
108
|
|
|
return; |
|
109
|
|
|
} |
|
110
|
|
|
|
|
111
|
|
|
usort($statics->contents, array('Kint_Parser_ClassStatics', 'sort')); |
|
112
|
|
|
|
|
113
|
|
|
$o->addRepresentation($statics); |
|
114
|
|
|
} |
|
115
|
|
|
|
|
116
|
|
|
private static function sort(Kint_Object $a, Kint_Object $b) |
|
117
|
|
|
{ |
|
118
|
|
|
$sort = ((int) $a->const) - ((int) $b->const); |
|
119
|
|
|
if ($sort) { |
|
120
|
|
|
return $sort; |
|
121
|
|
|
} |
|
122
|
|
|
|
|
123
|
|
|
$sort = Kint_Object::sortByAccess($a, $b); |
|
124
|
|
|
if ($sort) { |
|
125
|
|
|
return $sort; |
|
126
|
|
|
} |
|
127
|
|
|
|
|
128
|
|
|
return Kint_Object_Instance::sortByHierarchy($a->owner_class, $b->owner_class); |
|
129
|
|
|
} |
|
130
|
|
|
} |
|
131
|
|
|
|
Our type inference engine in quite powerful, but sometimes the code does not provide enough clues to go by. In these cases we request you to add a
@returnannotation as described here.