forked from mgtcommerce/Mgt_Developertoolbar
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathregistration.php
105 lines (91 loc) · 3.24 KB
/
registration.php
1
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
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
<?php
if (PHP_SAPI != 'cli') {
$_SERVER['MAGE_PROFILER_STAT'] = new \Mgt\DeveloperToolbar\Model\Profiler\Driver\Standard\Stat();
\Magento\Framework\Profiler::applyConfig(
[
'drivers' => [
[
'output' => 'Mgt\DeveloperToolbar\Model\Driver\Output\Zero',
'stat' => $_SERVER['MAGE_PROFILER_STAT'],
]
]
],
BP,
false
);
}
\Magento\Framework\Component\ComponentRegistrar::register(
\Magento\Framework\Component\ComponentRegistrar::MODULE,
'Mgt_DeveloperToolbar',
__DIR__
);
if (!function_exists('dumpDie')) {
function dumpDie(...$argc)
{
print_r('<pre><code>');
var_dump(...$argc);
print_r('</code></pre>');
}
}
if (!function_exists('consoleLog')) {
function consoleLog(...$argc)
{
$out = array_shift($argc);
if (!is_array($out)) {
$out = [$out];
}
// array_unshift($out, __FILE__ . ' :: ' . __LINE__);
$backtrace = \Spatie\Backtrace\Backtrace::create() // @phpstan-ignore-line
->withArguments()
->limit(2);
$trace = $backtrace->frames();
$out[] = $trace[1]->file . ' :: ' . $trace[1]->lineNumber;
// $out = array_map(function($val){return sprintf("'%s'", $val);}, $out);
// $out = http_build_query($out,'',', ');
// $out = '"' . json_encode($out) . '"';
$jsonOptions = JSON_PARTIAL_OUTPUT_ON_ERROR | JSON_HEX_TAG | JSON_HEX_APOS | JSON_HEX_AMP | JSON_HEX_QUOT;
$out = json_encode($out, $jsonOptions);
print_r('<script>console.log(' . $out . ');</script>');
}
}
if (!function_exists('consoleTrace')) {
function consoleTrace($limit = 20)
{
$applicationPath = BP;
$backtrace = \Spatie\Backtrace\Backtrace::create() // @phpstan-ignore-line
->withArguments()
// ->reduceArguments()
->applicationPath($applicationPath ?? '')
->limit($limit)
// ->withObject()
// ->trimFilePaths()
;
$trace = $backtrace->frames();//->toArray();
$trace = array_map(function($frame) {
$line = $frame->getSnippetAsString(1);
$line = preg_replace('!\s+!', ' ', $line);
// $line = str_pad($line, 120, ' ');
$file = $frame->file;
if (substr($file, 0, strlen(BP)) == BP) {
$file = substr($file, strlen(BP));
}
// $file = str_pad($file, 100, ' ');
$snippet = $frame->getSnippetAsString(10);
$snippet = str_replace('\n', "\n", $snippet);
return [
'line' => $frame->lineNumber,
'code_line' => $line,
'file' => $file,
'class' => $frame->class,
'method' => $frame->method,
'args' => $frame->arguments,
'snippet' => $snippet,
];
}, $trace);
$out = $trace;
array_shift($out);
$jsonOptions = JSON_PARTIAL_OUTPUT_ON_ERROR | JSON_HEX_TAG | JSON_HEX_APOS | JSON_HEX_AMP | JSON_HEX_QUOT;
$out = json_encode($out, $jsonOptions);
print_r('<script>console.table(' . $out . ');</script>');
}
}