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\Object; |
27: | |
28: | use Kint\Object\Representation\Representation; |
29: | use Kint\Object\Representation\SourceRepresentation; |
30: | use ReflectionFunction; |
31: | use ReflectionMethod; |
32: | |
33: | class TraceFrameObject extends BasicObject |
34: | { |
35: | public $trace; |
36: | public $hints = array('trace_frame'); |
37: | |
38: | public function __construct(BasicObject $base, array $raw_frame) |
39: | { |
40: | parent::__construct(); |
41: | |
42: | $this->transplant($base); |
43: | |
44: | $this->trace = array( |
45: | 'function' => isset($raw_frame['function']) ? $raw_frame['function'] : null, |
46: | 'line' => isset($raw_frame['line']) ? $raw_frame['line'] : null, |
47: | 'file' => isset($raw_frame['file']) ? $raw_frame['file'] : null, |
48: | 'class' => isset($raw_frame['class']) ? $raw_frame['class'] : null, |
49: | 'type' => isset($raw_frame['type']) ? $raw_frame['type'] : null, |
50: | 'object' => null, |
51: | 'args' => null, |
52: | ); |
53: | |
54: | if ($this->trace['class'] && \method_exists($this->trace['class'], $this->trace['function'])) { |
55: | $func = new ReflectionMethod($this->trace['class'], $this->trace['function']); |
56: | $this->trace['function'] = new MethodObject($func); |
57: | } elseif (!$this->trace['class'] && \function_exists($this->trace['function'])) { |
58: | $func = new ReflectionFunction($this->trace['function']); |
59: | $this->trace['function'] = new MethodObject($func); |
60: | } |
61: | |
62: | foreach ($this->value->contents as $frame_prop) { |
63: | if ('object' === $frame_prop->name) { |
64: | $this->trace['object'] = $frame_prop; |
65: | $this->trace['object']->name = null; |
66: | $this->trace['object']->operator = BasicObject::OPERATOR_NONE; |
67: | } |
68: | if ('args' === $frame_prop->name) { |
69: | $this->trace['args'] = $frame_prop->value->contents; |
70: | |
71: | if ($this->trace['function'] instanceof MethodObject) { |
72: | foreach (\array_values($this->trace['function']->parameters) as $param) { |
73: | if (isset($this->trace['args'][$param->position])) { |
74: | $this->trace['args'][$param->position]->name = $param->getName(); |
75: | } |
76: | } |
77: | } |
78: | } |
79: | } |
80: | |
81: | $this->clearRepresentations(); |
82: | |
83: | if (isset($this->trace['file'], $this->trace['line']) && \is_readable($this->trace['file'])) { |
84: | $this->addRepresentation(new SourceRepresentation($this->trace['file'], $this->trace['line'])); |
85: | } |
86: | |
87: | if ($this->trace['args']) { |
88: | $args = new Representation('Arguments'); |
89: | $args->contents = $this->trace['args']; |
90: | $this->addRepresentation($args); |
91: | } |
92: | |
93: | if ($this->trace['object']) { |
94: | $callee = new Representation('object'); |
95: | $callee->label = 'Callee object ['.$this->trace['object']->classname.']'; |
96: | $callee->contents[] = $this->trace['object']; |
97: | $this->addRepresentation($callee); |
98: | } |
99: | } |
100: | } |
101: | |