|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* Debugger basic file. |
|
4
|
|
|
* |
|
5
|
|
|
* @package App |
|
6
|
|
|
* |
|
7
|
|
|
* @copyright YetiForce S.A. |
|
8
|
|
|
* @license YetiForce Public License 6.5 (licenses/LicenseEN.txt or yetiforce.com) |
|
9
|
|
|
* @author Mariusz Krzaczkowski <[email protected]> |
|
10
|
|
|
*/ |
|
11
|
|
|
|
|
12
|
|
|
namespace App; |
|
13
|
|
|
|
|
14
|
|
|
use DebugBar\DataCollector; |
|
15
|
|
|
|
|
16
|
|
|
/** |
|
17
|
|
|
* Debuger basic class. |
|
18
|
|
|
*/ |
|
19
|
|
|
class Debuger |
|
20
|
|
|
{ |
|
21
|
|
|
/** |
|
22
|
|
|
* @var \DebugBar\Debuger |
|
|
|
|
|
|
23
|
|
|
*/ |
|
24
|
|
|
protected static $debugBar; |
|
25
|
|
|
|
|
26
|
|
|
/** |
|
27
|
|
|
* Initiating debugging console. |
|
28
|
|
|
* |
|
29
|
|
|
* @return \App\DebugBar\Debuger |
|
|
|
|
|
|
30
|
|
|
*/ |
|
31
|
|
|
public static function initConsole() |
|
32
|
2 |
|
{ |
|
33
|
|
|
if (\App\Config::debug('DISPLAY_DEBUG_CONSOLE') && static::consoleIsActive()) { |
|
34
|
2 |
|
$debugbar = new Debug\DebugBar\DebugBar(); |
|
35
|
2 |
|
$debugbar->addCollector(new DataCollector\PhpInfoCollector()); |
|
36
|
2 |
|
$debugbar->addCollector(new DataCollector\ExceptionsCollector()); |
|
37
|
2 |
|
$debugbar->addCollector(new DataCollector\RequestDataCollector()); |
|
38
|
2 |
|
$debugbar->addCollector(new DataCollector\MemoryCollector()); |
|
39
|
2 |
|
$debugbar->addCollector(new DataCollector\TimeDataCollector()); |
|
40
|
1 |
|
if (\App\Config::debug('DISPLAY_LOGS_IN_CONSOLE')) { |
|
41
|
|
|
$debugbar->addCollector(new Debug\DebugBarLogs()); |
|
42
|
2 |
|
} |
|
43
|
|
|
if (\App\Config::debug('DISPLAY_CONFIG_IN_CONSOLE')) { |
|
44
|
2 |
|
$debugbar->addCollector(new \DebugBar\DataCollector\ConfigCollector([ |
|
45
|
|
|
'debug' => \App\Config::debug(), |
|
46
|
|
|
'developer' => \App\Config::developer(), |
|
47
|
|
|
'performance' => \App\Config::performance(), |
|
48
|
|
|
'api' => \App\Config::api(), |
|
49
|
|
|
'security' => \App\Config::security(), |
|
50
|
|
|
'search' => \App\Config::search(), |
|
51
|
|
|
'sounds' => \App\Config::sounds(), |
|
52
|
1 |
|
'relation' => \App\Config::relation(), |
|
53
|
|
|
])); |
|
54
|
1 |
|
} |
|
55
|
|
|
static::$debugBar = $debugbar; |
|
|
|
|
|
|
56
|
|
|
} |
|
57
|
|
|
} |
|
58
|
|
|
|
|
59
|
|
|
/** |
|
60
|
|
|
* Get Debuger instance. |
|
61
|
|
|
* |
|
62
|
1 |
|
* @return \App\Debug\DebugBar\DebugBar |
|
63
|
|
|
*/ |
|
64
|
1 |
|
public static function getDebugBar() |
|
65
|
|
|
{ |
|
66
|
|
|
return static::$debugBar; |
|
67
|
|
|
} |
|
68
|
|
|
|
|
69
|
|
|
/** |
|
70
|
|
|
* Checking is active debugging. |
|
71
|
|
|
* |
|
72
|
3 |
|
* @return bool |
|
73
|
|
|
*/ |
|
74
|
3 |
|
public static function isDebugBar() |
|
75
|
|
|
{ |
|
76
|
|
|
return isset(static::$debugBar); |
|
77
|
1 |
|
} |
|
78
|
|
|
|
|
79
|
1 |
|
public static function addLogs($message, $level, $traces) |
|
80
|
1 |
|
{ |
|
81
|
|
|
if (isset(static::$debugBar['logs'])) { |
|
82
|
1 |
|
static::$debugBar['logs']->addMessage($message, $level, $traces); |
|
83
|
|
|
} |
|
84
|
|
|
} |
|
85
|
|
|
|
|
86
|
|
|
/** |
|
87
|
1 |
|
* Initiating debugging. |
|
88
|
|
|
*/ |
|
89
|
1 |
|
public static function init() |
|
90
|
1 |
|
{ |
|
91
|
|
|
$targets = []; |
|
92
|
1 |
|
if (\App\Config::debug('LOG_TO_FILE')) { |
|
93
|
1 |
|
$levels = \App\Config::debug('LOG_LEVELS'); |
|
94
|
1 |
|
$target = [ |
|
95
|
|
|
'class' => 'App\Log\FileTarget', |
|
96
|
1 |
|
]; |
|
97
|
|
|
if (false !== $levels) { |
|
98
|
1 |
|
$target['levels'] = $levels; |
|
99
|
1 |
|
} |
|
100
|
|
|
$targets['file'] = $target; |
|
101
|
1 |
|
} |
|
102
|
|
|
if (\App\Config::debug('LOG_TO_PROFILE')) { |
|
103
|
1 |
|
$levels = \App\Config::debug('LOG_LEVELS'); |
|
104
|
1 |
|
$target = [ |
|
105
|
|
|
'class' => 'App\Log\Profiling', |
|
106
|
1 |
|
]; |
|
107
|
|
|
if (false !== $levels) { |
|
108
|
1 |
|
$target['levels'] = $levels; |
|
109
|
1 |
|
} |
|
110
|
|
|
$targets['profiling'] = $target; |
|
111
|
1 |
|
} |
|
112
|
|
|
\Yii::createObject([ |
|
113
|
1 |
|
'class' => 'yii\log\Dispatcher', |
|
114
|
1 |
|
'traceLevel' => \App\Config::debug('LOG_TRACE_LEVEL'), |
|
115
|
1 |
|
'targets' => $targets, |
|
116
|
1 |
|
]); |
|
117
|
|
|
} |
|
118
|
1 |
|
|
|
119
|
|
|
/** |
|
120
|
|
|
* Checking console is active. |
|
121
|
|
|
* |
|
122
|
|
|
* @return bool |
|
123
|
|
|
*/ |
|
124
|
|
|
public static function consoleIsActive() |
|
125
|
2 |
|
{ |
|
126
|
|
|
$ips = \Config\Debug::$DEBUG_CONSOLE_ALLOWED_IPS; |
|
127
|
2 |
|
if (false === $ips || (\is_string($ips) && RequestUtil::getRemoteIP(true) === $ips) || (\is_array($ips) && \in_array(RequestUtil::getRemoteIP(true), $ips))) { |
|
128
|
2 |
|
if (\Config\Debug::$DEBUG_CONSOLE_ALLOWED_USERS && !\in_array(\App\User::getCurrentUserRealId(), \Config\Debug::$DEBUG_CONSOLE_ALLOWED_USERS)) { |
|
|
|
|
|
|
129
|
2 |
|
return false; |
|
130
|
|
|
} |
|
131
|
1 |
|
return true; |
|
132
|
|
|
} |
|
133
|
|
|
return false; |
|
134
|
|
|
} |
|
135
|
|
|
|
|
136
|
|
|
/** |
|
137
|
|
|
* Generates a backtrace. |
|
138
|
|
|
* |
|
139
|
|
|
* @param int $minLevel |
|
140
|
|
|
* @param int $maxLevel |
|
141
|
|
|
* @param string $sep |
|
142
|
|
|
* |
|
143
|
6389 |
|
* @return string |
|
144
|
|
|
*/ |
|
145
|
6389 |
|
public static function getBacktrace($minLevel = 1, $maxLevel = 0, $sep = '#') |
|
146
|
6389 |
|
{ |
|
147
|
6389 |
|
$trace = ''; |
|
148
|
6389 |
|
foreach (debug_backtrace() as $k => $v) { |
|
149
|
|
|
if ($k < $minLevel) { |
|
150
|
6389 |
|
continue; |
|
151
|
6389 |
|
} |
|
152
|
6389 |
|
$l = $k - $minLevel; |
|
153
|
6389 |
|
$args = ''; |
|
154
|
6389 |
|
if (isset($v['args'])) { |
|
155
|
6389 |
|
foreach ($v['args'] as &$arg) { |
|
156
|
6006 |
|
if (!\is_array($arg) && !\is_object($arg) && !\is_resource($arg)) { |
|
157
|
150 |
|
$args .= var_export($arg, true); |
|
158
|
150 |
|
} elseif (\is_array($arg)) { |
|
159
|
147 |
|
$args .= '['; |
|
160
|
147 |
|
foreach ($arg as &$a) { |
|
161
|
35 |
|
$val = $a; |
|
162
|
35 |
|
if (\is_array($a) || \is_object($a) || \is_resource($a)) { |
|
163
|
9 |
|
$val = \gettype($a); |
|
164
|
|
|
if (\is_object($a)) { |
|
165
|
|
|
$val .= '(' . \get_class($a) . ')'; |
|
166
|
147 |
|
} |
|
167
|
|
|
} |
|
168
|
150 |
|
$args .= $val . ','; |
|
169
|
|
|
} |
|
170
|
6389 |
|
$args = rtrim($args, ',') . ']'; |
|
171
|
|
|
} |
|
172
|
6389 |
|
$args .= ','; |
|
173
|
|
|
} |
|
174
|
6389 |
|
$args = rtrim($args, ','); |
|
175
|
6389 |
|
} |
|
176
|
6389 |
|
$trace .= "$sep$l"; |
|
177
|
|
|
if (isset($v['line'])) { |
|
178
|
6389 |
|
$trace .= " {$v['file']}:{$v['line']}"; |
|
179
|
6389 |
|
} |
|
180
|
6389 |
|
$trace .= ' >> ' . (isset($v['class']) ? $v['class'] . '->' : '') . "{$v['function']}($args)" . PHP_EOL; |
|
181
|
6388 |
|
unset($args, $val, $v, $k, $a); |
|
182
|
|
|
if (0 !== $maxLevel && $l >= $maxLevel) { |
|
183
|
|
|
break; |
|
184
|
6389 |
|
} |
|
185
|
|
|
} |
|
186
|
|
|
return rtrim(str_replace(ROOT_DIRECTORY . \DIRECTORY_SEPARATOR, '', $trace), PHP_EOL); |
|
187
|
|
|
} |
|
188
|
|
|
} |
|
189
|
|
|
|
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths