|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
class Kint_Parser_SimpleXMLElement extends Kint_Parser_Plugin |
|
4
|
|
|
{ |
|
5
|
|
|
/** |
|
6
|
|
|
* Show all properties and methods. |
|
7
|
|
|
* |
|
8
|
|
|
* @var bool |
|
9
|
|
|
*/ |
|
10
|
|
|
public static $verbose = false; |
|
11
|
|
|
|
|
12
|
|
|
public function getTypes() |
|
13
|
|
|
{ |
|
14
|
|
|
return array('object'); |
|
15
|
|
|
} |
|
16
|
|
|
|
|
17
|
|
|
public function getTriggers() |
|
|
|
|
|
|
18
|
|
|
{ |
|
19
|
|
|
return Kint_Parser::TRIGGER_SUCCESS; |
|
20
|
|
|
} |
|
21
|
|
|
|
|
22
|
|
|
public function parse(&$var, Kint_Object &$o, $trigger) |
|
23
|
|
|
{ |
|
24
|
|
|
if (!$var instanceof SimpleXMLElement) { |
|
25
|
|
|
return; |
|
26
|
|
|
} |
|
27
|
|
|
|
|
28
|
|
|
$o->hints[] = 'simplexml_element'; |
|
29
|
|
|
|
|
30
|
|
|
if (!self::$verbose) { |
|
31
|
|
|
$o->removeRepresentation('properties'); |
|
32
|
|
|
$o->removeRepresentation('iterator'); |
|
33
|
|
|
$o->removeRepresentation('methods'); |
|
34
|
|
|
} |
|
35
|
|
|
|
|
36
|
|
|
// Attributes |
|
37
|
|
|
$a = new Kint_Object_Representation('Attributes'); |
|
38
|
|
|
|
|
39
|
|
|
$base_obj = new Kint_Object(); |
|
40
|
|
|
$base_obj->depth = $o->depth; |
|
41
|
|
|
|
|
42
|
|
|
if ($o->access_path) { |
|
|
|
|
|
|
43
|
|
|
$base_obj->access_path = '(string) '.$o->access_path; |
|
44
|
|
|
} |
|
45
|
|
|
|
|
46
|
|
|
if ($var->attributes()) { |
|
47
|
|
|
$attribs = iterator_to_array($var->attributes()); |
|
48
|
|
|
$attribs = array_map('strval', $attribs); |
|
49
|
|
|
} else { |
|
50
|
|
|
$attribs = array(); |
|
51
|
|
|
} |
|
52
|
|
|
|
|
53
|
|
|
// XML attributes are by definition strings and don't have children, |
|
54
|
|
|
// so up the depth limit in case we're just below the limit since |
|
55
|
|
|
// there won't be any recursive stuff anyway. |
|
56
|
|
|
$depth_stash = $this->parser->max_depth; |
|
57
|
|
|
$this->parser->max_depth = 0; |
|
58
|
|
|
$a->contents = $this->parser->parse($attribs, $base_obj); |
|
|
|
|
|
|
59
|
|
|
$this->parser->max_depth = $depth_stash; |
|
60
|
|
|
|
|
61
|
|
|
$a->contents = $a->contents->value->contents; |
|
62
|
|
|
|
|
63
|
|
|
$o->addRepresentation($a, 0); |
|
64
|
|
|
|
|
65
|
|
|
// Children |
|
66
|
|
|
// We need to check children() separately from the values we already parsed because |
|
67
|
|
|
// text contents won't show up in children() but they will show up in properties. |
|
68
|
|
|
// |
|
69
|
|
|
// Why do we still need to check for attributes if we already have an attributes() |
|
70
|
|
|
// method? Hell if I know! |
|
71
|
|
|
$children = $var->children(); |
|
72
|
|
|
|
|
73
|
|
|
if ($o->value) { |
|
74
|
|
|
$c = new Kint_Object_Representation('Children'); |
|
75
|
|
|
|
|
76
|
|
|
foreach ($o->value->contents as $value) { |
|
77
|
|
|
if ($value->name === '@attributes') { |
|
78
|
|
|
continue; |
|
79
|
|
|
} elseif (isset($children->{$value->name})) { |
|
80
|
|
|
$i = 0; |
|
81
|
|
|
|
|
82
|
|
|
while (isset($children->{$value->name}[$i])) { |
|
83
|
|
|
$base_obj = new Kint_Object(); |
|
84
|
|
|
$base_obj->depth = $o->depth + 1; |
|
85
|
|
|
$base_obj->name = $value->name; |
|
86
|
|
|
if ($value->access_path) { |
|
87
|
|
|
$base_obj->access_path = $value->access_path.'['.$i.']'; |
|
88
|
|
|
} |
|
89
|
|
|
|
|
90
|
|
|
$value = $this->parser->parse($children->{$value->name}[$i], $base_obj); |
|
91
|
|
|
|
|
92
|
|
|
if ($value->access_path && $value->type === 'string') { |
|
93
|
|
|
$value->access_path = '(string) '.$value->access_path; |
|
94
|
|
|
} |
|
95
|
|
|
|
|
96
|
|
|
$c->contents[] = $value; |
|
97
|
|
|
|
|
98
|
|
|
++$i; |
|
99
|
|
|
} |
|
100
|
|
|
} |
|
101
|
|
|
} |
|
102
|
|
|
|
|
103
|
|
|
$o->size = count($c->contents); |
|
104
|
|
|
|
|
105
|
|
|
if (!$o->size) { |
|
106
|
|
|
$o->size = null; |
|
107
|
|
|
|
|
108
|
|
|
if (strlen((string) $var)) { |
|
109
|
|
|
$base_obj = new Kint_Object_Blob(); |
|
110
|
|
|
$base_obj->depth = $o->depth + 1; |
|
111
|
|
|
$base_obj->name = $o->name; |
|
112
|
|
|
if ($o->access_path) { |
|
|
|
|
|
|
113
|
|
|
$base_obj->access_path = '(string) '.$o->access_path; |
|
114
|
|
|
} |
|
115
|
|
|
|
|
116
|
|
|
$value = (string) $var; |
|
117
|
|
|
|
|
118
|
|
|
$depth_stash = $this->parser->max_depth; |
|
119
|
|
|
$this->parser->max_depth = 0; |
|
120
|
|
|
$value = $this->parser->parse($value, $base_obj); |
|
121
|
|
|
$this->parser->max_depth = $depth_stash; |
|
122
|
|
|
|
|
123
|
|
|
$c = new Kint_Object_Representation('Contents'); |
|
124
|
|
|
$c->implicit_label = true; |
|
125
|
|
|
$c->contents = array($value); |
|
126
|
|
|
} |
|
127
|
|
|
} |
|
128
|
|
|
|
|
129
|
|
|
$o->addRepresentation($c, 0); |
|
130
|
|
|
} |
|
131
|
|
|
} |
|
132
|
|
|
} |
|
133
|
|
|
|
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.