1: <?php
2:
3: /*
4: * The MIT License (MIT)
5: *
6: * Copyright (c) 2013 Jonathan Vollebregt (jnvsor@gmail.com), Rokas Šleinius (raveren@gmail.com)
7: *
8: * Permission is hereby granted, free of charge, to any person obtaining a copy of
9: * this software and associated documentation files (the "Software"), to deal in
10: * the Software without restriction, including without limitation the rights to
11: * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
12: * the Software, and to permit persons to whom the Software is furnished to do so,
13: * subject to the following conditions:
14: *
15: * The above copyright notice and this permission notice shall be included in all
16: * copies or substantial portions of the Software.
17: *
18: * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19: * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
20: * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
21: * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
22: * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
23: * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
24: */
25:
26: namespace Kint\Parser;
27:
28: use Kint\Object\BasicObject;
29: use Kint\Object\TraceFrameObject;
30: use Kint\Object\TraceObject;
31: use Kint\Utils;
32:
33: class TracePlugin extends Plugin
34: {
35: public static $blacklist = array('spl_autoload_call');
36:
37: public function getTypes()
38: {
39: return array('array');
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 (!$o->value) {
50: return;
51: }
52:
53: $trace = $this->parser->getCleanArray($var);
54:
55: if (\count($trace) !== \count($o->value->contents) || !Utils::isTrace($trace)) {
56: return;
57: }
58:
59: $traceobj = new TraceObject();
60: $traceobj->transplant($o);
61: $rep = $traceobj->value;
62:
63: $old_trace = $rep->contents;
64:
65: Utils::normalizeAliases(self::$blacklist);
66:
67: $rep->contents = array();
68:
69: foreach ($old_trace as $frame) {
70: $index = $frame->name;
71:
72: if (!isset($trace[$index]['function'])) {
73: // Something's very very wrong here, but it's probably a plugin's fault
74: continue;
75: }
76:
77: if (Utils::traceFrameIsListed($trace[$index], self::$blacklist)) {
78: continue;
79: }
80:
81: $rep->contents[$index] = new TraceFrameObject($frame, $trace[$index]);
82: }
83:
84: \ksort($rep->contents);
85: $rep->contents = \array_values($rep->contents);
86:
87: $traceobj->clearRepresentations();
88: $traceobj->addRepresentation($rep);
89: $traceobj->size = \count($rep->contents);
90: $o = $traceobj;
91: }
92: }
93: