1 | <?php |
||
2 | /** |
||
3 | * This file is part of the O2System Framework package. |
||
4 | * |
||
5 | * For the full copyright and license information, please view the LICENSE |
||
6 | * file that was distributed with this source code. |
||
7 | * |
||
8 | * @author Steeve Andrian Salim |
||
9 | * @copyright Copyright (c) Steeve Andrian Salim |
||
10 | */ |
||
11 | |||
12 | // ------------------------------------------------------------------------ |
||
13 | |||
14 | namespace O2System\Gear; |
||
15 | |||
16 | // ------------------------------------------------------------------------ |
||
17 | |||
18 | /** |
||
19 | * O2System Gear Debug |
||
20 | * |
||
21 | * @package O2System\Gear |
||
22 | */ |
||
23 | class Debugger |
||
24 | { |
||
25 | /** |
||
26 | * Debugger::$chronology |
||
27 | * |
||
28 | * List of Debug Chronology |
||
29 | * |
||
30 | * @access private |
||
31 | * @static |
||
32 | * |
||
33 | * @type array |
||
34 | */ |
||
35 | private static $chronology = []; |
||
36 | |||
37 | // ------------------------------------------------------------------------ |
||
38 | |||
39 | /** |
||
40 | * Debugger::start |
||
41 | * |
||
42 | * Start Debug Process |
||
43 | * |
||
44 | * @access public |
||
45 | * @static static method |
||
46 | */ |
||
47 | public static function start() |
||
48 | { |
||
49 | static::$chronology = []; |
||
0 ignored issues
–
show
Bug
introduced
by
![]() |
|||
50 | static::$chronology[] = static::whereCall(__CLASS__ . '::start()', 'debug_start()'); |
||
51 | } |
||
52 | |||
53 | // ------------------------------------------------------------------------ |
||
54 | |||
55 | /** |
||
56 | * Debugger::whereCall |
||
57 | * |
||
58 | * Where Call Method |
||
59 | * |
||
60 | * Finding where the call is made |
||
61 | * |
||
62 | * @access private |
||
63 | * |
||
64 | * @param $call String Call Method |
||
65 | * |
||
66 | * @return Trace Object |
||
67 | */ |
||
68 | private static function whereCall($call, $helper) |
||
69 | { |
||
70 | $tracer = new Trace(); |
||
71 | |||
72 | foreach ($tracer->getChronology() as $trace) { |
||
73 | if ($trace->call === $helper) { |
||
74 | return $trace; |
||
75 | break; |
||
0 ignored issues
–
show
break is not strictly necessary here and could be removed.
The switch ($x) {
case 1:
return 'foo';
break; // This break is not necessary and can be left off.
}
If you would like to keep this construct to be consistent with other ![]() |
|||
76 | } elseif ($trace->call === $call) { |
||
77 | return $trace; |
||
78 | break; |
||
79 | } |
||
80 | } |
||
81 | } |
||
82 | |||
83 | // ------------------------------------------------------------------------ |
||
84 | |||
85 | /** |
||
86 | * Debugger::line |
||
87 | * |
||
88 | * Add debug line output |
||
89 | * |
||
90 | * @param mixed $expression |
||
91 | * @param bool $export |
||
92 | */ |
||
93 | public static function line($expression, $export = false) |
||
94 | { |
||
95 | $trace = static::whereCall(__CLASS__ . '::line()', 'debug_line()'); |
||
96 | |||
97 | if ($export === true) { |
||
98 | $trace->expression = var_export($expression, true); |
||
0 ignored issues
–
show
|
|||
99 | } else { |
||
100 | $trace->expression = var_format($expression); |
||
101 | } |
||
102 | |||
103 | static::$chronology[] = $trace; |
||
0 ignored issues
–
show
|
|||
104 | } |
||
105 | |||
106 | // ------------------------------------------------------------------------ |
||
107 | |||
108 | /** |
||
109 | * Debugger::marker |
||
110 | * |
||
111 | * Set Debug Marker |
||
112 | */ |
||
113 | public static function marker() |
||
114 | { |
||
115 | $trace = static::whereCall(__CLASS__ . '::marker()', 'debug_marker()'); |
||
116 | static::$chronology[] = $trace; |
||
0 ignored issues
–
show
|
|||
117 | } |
||
118 | |||
119 | // ------------------------------------------------------------------------ |
||
120 | |||
121 | /** |
||
122 | * Debugger::stop |
||
123 | * |
||
124 | * Stop Debug |
||
125 | */ |
||
126 | public static function stop() |
||
127 | { |
||
128 | static::$chronology[] = static::whereCall(__CLASS__ . '::stop()', 'debug_stop()'); |
||
0 ignored issues
–
show
|
|||
129 | static::render(); |
||
130 | } |
||
131 | |||
132 | // ------------------------------------------------------------------------ |
||
133 | |||
134 | /** |
||
135 | * Debugger::render |
||
136 | */ |
||
137 | public static function render() |
||
138 | { |
||
139 | $trace = static::$chronology; |
||
0 ignored issues
–
show
|
|||
140 | |||
141 | ob_start(); |
||
142 | include __DIR__ . '/Views/Debugger.php'; |
||
143 | $output = ob_get_contents(); |
||
144 | ob_end_clean(); |
||
145 | |||
146 | static::$chronology = []; |
||
147 | |||
148 | echo $output; |
||
149 | } |
||
150 | } |