Skip to content
This repository was archived by the owner on Sep 6, 2023. It is now read-only.

Commit 489a249

Browse files
committed
Улучшения
1 parent 7d4daf3 commit 489a249

File tree

2 files changed

+115
-0
lines changed

2 files changed

+115
-0
lines changed
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<?php
2+
// Добавляем дебаг-бар
3+
\Bitrix\Main\EventManager::getInstance()->addEventHandler(
4+
"main",
5+
"OnEndBufferContent",
6+
[
7+
"\\GGrach\\BitrixDebugger\\Events\\OnEndBufferContent",
8+
"addDebugBar"
9+
]
10+
);
Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
<?php
2+
3+
/**
4+
* Красивая подстветка дебага
5+
*
6+
* @param type $data
7+
* @return type
8+
*/
9+
function ggrach_highlight_data($data = [], $needHideBlocks = false) {
10+
11+
$viewResult = '';
12+
13+
$highlightItem = function ($in, $opened, $margin = 5) use (&$highlightItem, $needHideBlocks) {
14+
15+
$viewRes = '';
16+
17+
if (!\is_object($in) && !\is_array($in)) {
18+
return $in;
19+
}
20+
21+
if ($needHideBlocks == true) {
22+
$opened = '';
23+
}
24+
25+
foreach ($in as $key => $value) {
26+
if (\is_object($value) || \is_array($value)) {
27+
$viewRes .= '<details style="margin-left:' . $margin . 'px" ' . $opened . '>';
28+
$viewRes .= '<summary style="cursor: pointer; margin-top: 5px; margin-bottom: 5px; text-decoration: underline;">';
29+
$viewRes .= (is_object($value)) ? $key . ' {' . count((array) $value) . '}' : $key . ' [' . count($value) . ']';
30+
$viewRes .= '</summary>';
31+
$viewRes .= $highlightItem($value, $opened, $margin + 5);
32+
$viewRes .= '</details>';
33+
} else {
34+
switch (gettype($value)) {
35+
case 'string':
36+
$bgc = 'red';
37+
$value = \strip_tags($value);
38+
if (\strlen($value) > 200) {
39+
$value = '[Very long string]';
40+
}
41+
42+
break;
43+
case 'integer':
44+
$bgc = 'green';
45+
break;
46+
}
47+
$viewRes .= '<div style="margin-left:' . $margin . 'px">' . $key . ' : '
48+
. '<span style="color:' . $bgc . '">' . $value . '</span> '
49+
. '<span style="color: blue;">(' . gettype($value) . ')</span>'
50+
. '</div>';
51+
}
52+
}
53+
54+
return $viewRes;
55+
};
56+
57+
$highlight = function ($in, $opened = true) use ($highlightItem) {
58+
59+
$view = '<div>';
60+
61+
if ($opened) {
62+
$opened = ' open';
63+
}
64+
65+
if (is_object($in) or is_array($in)) {
66+
$view .= '<details' . $opened . '>';
67+
$view .= '<summary style="cursor: pointer; margin-top: 5px; margin-bottom: 5px; text-decoration: underline;">';
68+
$view .= (is_object($in)) ? 'Object {' . count((array) $in) . '}' : 'Array [' . count($in) . ']';
69+
$view .= '</summary>';
70+
$view .= $highlightItem($in, $opened);
71+
$view .= '</details>';
72+
} else {
73+
switch (gettype($in)) {
74+
case 'string':
75+
$bgc = 'red';
76+
77+
$in = \strip_tags($in);
78+
79+
if (\strlen($in) > 200) {
80+
$in = '[Очень длинная строка]';
81+
}
82+
83+
break;
84+
case 'integer':
85+
$bgc = 'green';
86+
break;
87+
}
88+
89+
$view .= '<div style="margin-left: 0px">'
90+
. '<span style="color:' . $bgc . '">' . $in . '</span> '
91+
. '<span style="color: blue;">(' . gettype($in) . ')</span>'
92+
. '</div>';
93+
}
94+
95+
96+
$view .= '</div>';
97+
98+
99+
return $view;
100+
};
101+
102+
$viewResult .= $highlight($data, !$needHideBlocks);
103+
104+
return $viewResult;
105+
}

0 commit comments

Comments
 (0)