1: | <?php |
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: | namespace Kint\Parser; |
27: | |
28: | use Closure; |
29: | use Kint\Object\BasicObject; |
30: | use Kint\Object\ClosureObject; |
31: | use Kint\Object\ParameterObject; |
32: | use Kint\Object\Representation\Representation; |
33: | use ReflectionFunction; |
34: | |
35: | class ClosurePlugin extends Plugin |
36: | { |
37: | public function getTypes() |
38: | { |
39: | return array('object'); |
40: | } |
41: | |
42: | public function getTriggers() |
43: | { |
44: | return Parser::TRIGGER_SUCCESS; |
45: | } |
46: | |
47: | public function parse(&$var, BasicObject &$o, $trigger) |
48: | { |
49: | if (!$var instanceof Closure) { |
50: | return; |
51: | } |
52: | |
53: | $object = new ClosureObject(); |
54: | $object->transplant($o); |
55: | $o = $object; |
56: | $object->removeRepresentation('properties'); |
57: | |
58: | $closure = new ReflectionFunction($var); |
59: | |
60: | $o->filename = $closure->getFileName(); |
61: | $o->startline = $closure->getStartLine(); |
62: | |
63: | foreach ($closure->getParameters() as $param) { |
64: | $o->parameters[] = new ParameterObject($param); |
65: | } |
66: | |
67: | $p = new Representation('Parameters'); |
68: | $p->contents = &$o->parameters; |
69: | $o->addRepresentation($p, 0); |
70: | |
71: | $statics = array(); |
72: | |
73: | if (\method_exists($closure, 'getClosureThis') && $v = $closure->getClosureThis()) { |
74: | $statics = array('this' => $v); |
75: | } |
76: | |
77: | if (\count($statics = $statics + $closure->getStaticVariables())) { |
78: | $statics_parsed = array(); |
79: | |
80: | foreach ($statics as $name => &$static) { |
81: | $obj = BasicObject::blank('$'.$name); |
82: | $obj->depth = $o->depth + 1; |
83: | $statics_parsed[$name] = $this->parser->parse($static, $obj); |
84: | if (null === $statics_parsed[$name]->value) { |
85: | $statics_parsed[$name]->access_path = null; |
86: | } |
87: | } |
88: | |
89: | $r = new Representation('Uses'); |
90: | $r->contents = $statics_parsed; |
91: | $o->addRepresentation($r, 0); |
92: | } |
93: | } |
94: | } |
95: | |