1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
class Kint_Parser_DOMIterator extends Kint_Parser_Plugin |
|
|
|
|
4
|
|
|
{ |
5
|
|
|
public function getTypes() |
6
|
|
|
{ |
7
|
|
|
return array('object'); |
8
|
|
|
} |
9
|
|
|
|
10
|
|
|
public function getTriggers() |
|
|
|
|
11
|
|
|
{ |
12
|
|
|
// Recursion should never happen, should always be stopped at the parent |
13
|
|
|
// DOMNode. Depth limit on the other hand we're going to skip since |
14
|
|
|
// that would show an empty iterator and rather useless. Let the depth |
15
|
|
|
// limit hit the children (DOMNodeList only has DOMNode as children) |
16
|
|
|
return Kint_Parser::TRIGGER_COMPLETE & ~Kint_Parser::TRIGGER_RECURSION; |
17
|
|
|
} |
18
|
|
|
|
19
|
|
|
public function parse(&$var, Kint_Object &$o, $trigger) |
|
|
|
|
20
|
|
|
{ |
21
|
|
|
if (!($var instanceof DOMNamedNodeMap || $var instanceof DOMNodeList)) { |
22
|
|
|
return; |
23
|
|
|
} |
24
|
|
|
|
25
|
|
|
$o->size = $var->length; |
26
|
|
|
if ($o->size === 0) { |
27
|
|
|
$o->replaceRepresentation(new Kint_Object_Representation('Iterator')); |
28
|
|
|
$o->size = null; |
29
|
|
|
|
30
|
|
|
return; |
31
|
|
|
} |
32
|
|
|
|
33
|
|
|
// Depth limit |
34
|
|
|
// Make empty iterator representation since we need it in DOMNode to point out depth limits |
35
|
|
|
if ($this->parser->max_depth && $o->depth + 1 >= $this->parser->max_depth) { |
36
|
|
|
$b = new Kint_Object(); |
|
|
|
|
37
|
|
|
$b->name = $o->classname.' Iterator Contents'; |
|
|
|
|
38
|
|
|
$b->access_path = 'iterator_to_array('.$o->access_path.')'; |
39
|
|
|
$b->depth = $o->depth + 1; |
40
|
|
|
$b->hints[] = 'depth_limit'; |
41
|
|
|
|
42
|
|
|
$r = new Kint_Object_Representation('Iterator'); |
|
|
|
|
43
|
|
|
$r->contents = array($b); |
44
|
|
|
$o->replaceRepresentation($r, 0); |
45
|
|
|
|
46
|
|
|
return; |
47
|
|
|
} |
48
|
|
|
|
49
|
|
|
// In 5.1 you can interate them but they're not traversable. |
50
|
|
|
// DomDoc. The gift that keeps on giving. |
51
|
|
|
if (!$var instanceof Traversable) { |
52
|
|
|
$data = array(); |
53
|
|
|
foreach ($var as $item) { |
54
|
|
|
$data[] = $item; |
55
|
|
|
} |
56
|
|
|
} else { |
57
|
|
|
$data = iterator_to_array($var); |
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
$r = new Kint_Object_Representation('Iterator'); |
61
|
|
|
$o->replaceRepresentation($r, 0); |
62
|
|
|
|
63
|
|
|
foreach ($data as $key => $item) { |
64
|
|
|
$base_obj = new Kint_Object(); |
|
|
|
|
65
|
|
|
$base_obj->depth = $o->depth + 1; |
|
|
|
|
66
|
|
|
$base_obj->name = $item->nodeName; |
|
|
|
|
67
|
|
|
|
68
|
|
|
if ($o->access_path) { |
|
|
|
|
69
|
|
|
if ($var instanceof DOMNamedNodeMap) { |
70
|
|
|
$base_obj->access_path = $o->access_path.'->getNamedItem('.var_export($key, true).')'; |
|
|
|
|
71
|
|
|
} elseif ($var instanceof DOMNodeList) { |
72
|
|
|
$base_obj->access_path = $o->access_path.'->item('.var_export($key, true).')'; |
|
|
|
|
73
|
|
|
} else { |
74
|
|
|
$base_obj->access_path = 'iterator_to_array('.$o->access_path.')'; |
|
|
|
|
75
|
|
|
} |
76
|
|
|
} |
77
|
|
|
|
78
|
|
|
$r->contents[] = $this->parser->parse($item, $base_obj); |
|
|
|
|
79
|
|
|
} |
80
|
|
|
} |
81
|
|
|
} |
82
|
|
|
|
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.