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

Commit 187dd25

Browse files
authored
Merge pull request #3 from ggrachdev/dev
0.03 beta
2 parents e627591 + 460e334 commit 187dd25

File tree

17 files changed

+174
-101
lines changed

17 files changed

+174
-101
lines changed
File renamed without changes.

assets/DebugBar/themes/general.css renamed to assets/DebugBar/css/themes/general.css

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@
8383
border-bottom: 1px solid #c3c3c3 !important;
8484
font-size: 13px !important;
8585
line-height: 16px !important;
86+
margin: 0 !important;
8687
}
8788

8889
.ggrach__debug_bar__log > pre > code {
191 KB
Loading

assets/DebugBar/js/initializer.js

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -61,8 +61,16 @@ Ggrach.Utils.User = {
6161

6262
Ggrach.Utils.DOM = {
6363

64+
hideOverlay: function () {
65+
Ggrach.Utils.DOM.getOverlay().style.display = 'none';
66+
},
67+
68+
showOverlay: function () {
69+
Ggrach.Utils.DOM.getOverlay().style.display = 'block';
70+
},
71+
6472
getDebugBarLogsType: function (type) {
65-
return document.querySelector('.ggrach__debug_bar__log[data-type-notice="' + type + '"]')
73+
return document.querySelector('.ggrach__debug_bar__log[data-type-notice="' + type + '"]');
6674
},
6775

6876
getDebugBarLogs: function () {
@@ -82,7 +90,7 @@ Ggrach.Handlers = {
8290

8391
// Нажатие клавиши esc
8492
onKeyEsc: function (e) {
85-
if ((e.key == 'Escape' || e.key == 'Esc' || e.keyCode == 27) && (e.target.nodeName == 'BODY')) {
93+
if ((e.key === 'Escape' || e.key === 'Esc' || e.keyCode == 27) && (e.target.nodeName === 'BODY')) {
8694

8795
if (document.querySelector('[data-type-notice].active'))
8896
{
@@ -116,13 +124,13 @@ Ggrach.Handlers = {
116124
e.target.classList.remove('active');
117125
document.querySelector('body').style.overflow = null;
118126
$targetLogPanel.style.display = 'none';
119-
Ggrach.Utils.DOM.getOverlay().style.display = 'none';
127+
Ggrach.Utils.DOM.hideOverlay();
120128
} else
121129
{
122130
e.target.classList.add('active');
123131
document.querySelector('body').style.overflow = 'hidden';
124132
$targetLogPanel.style.display = 'block';
125-
Ggrach.Utils.DOM.getOverlay().style.display = 'block';
133+
Ggrach.Utils.DOM.showOverlay();
126134
}
127135
}
128136
};

events.php

Lines changed: 8 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,10 @@
11
<?php
2-
32
// Добавляем дебаг-бар
4-
AddEventHandler("main", "OnEndBufferContent", "GgrachAddDebugBar");
5-
6-
function GgrachAddDebugBar(&$content) {
7-
8-
global $USER, $APPLICATION;
9-
10-
if (
11-
strpos($APPLICATION->GetCurDir(), "/bitrix/") !== false) {
12-
return;
13-
}
14-
15-
if ($APPLICATION->GetProperty("save_kernel") == "Y") {
16-
return;
17-
}
18-
19-
if(!\is_object($USER))
20-
{
21-
return;
22-
}
23-
24-
if(!$USER->IsAdmin())
25-
{
26-
return;
27-
}
28-
29-
$logData = \GGrach\BitrixDebugger\Representer\DebugBarRepresenter::render(GD());
30-
$content = \str_replace('</body>', $logData . '</body>', $content);
31-
}
3+
\Bitrix\Main\EventManager::getInstance()->addEventHandler(
4+
"main",
5+
"OnEndBufferContent",
6+
[
7+
"\\GGrach\\BitrixDebugger\\Events\\OnEndBufferContent",
8+
"addDebugBar"
9+
]
10+
);

initializer.php

Lines changed: 13 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -3,74 +3,27 @@
33
/**
44
* https://github.com/ggrachdev/BitrixDebugger
55
6-
* @version 0.02
6+
* @version 0.03 beta
77
*
88
* Пример дебага:
99
*
10-
* GD()->notice('Моя переменная', 'Моя переменная 2');
11-
* GD()->error('Моя переменная', 'Моя переменная 2');
12-
* GD()->warning('Моя переменная', 'Моя переменная 2');
13-
* GD()->success('Моя переменная', 'Моя переменная 2');
10+
* DD()->notice('Моя переменная', 'Моя переменная 2');
11+
* DD()->error('Моя переменная', 'Моя переменная 2');
12+
* DD()->warning('Моя переменная', 'Моя переменная 2');
13+
* DD()->success('Моя переменная', 'Моя переменная 2');
1414
*
1515
* Залогировать в файлы
16-
* GD()->noticeLog('Моя переменная', 'Моя переменная 2');
17-
* GD()->errorLog('Моя переменная', 'Моя переменная 2');
18-
* GD()->warningLog('Моя переменная', 'Моя переменная 2');
19-
* GD()->successLog('Моя переменная', 'Моя переменная 2');
16+
* DD()->noticeLog('Моя переменная', 'Моя переменная 2');
17+
* DD()->errorLog('Моя переменная', 'Моя переменная 2');
18+
* DD()->warningLog('Моя переменная', 'Моя переменная 2');
19+
* DD()->successLog('Моя переменная', 'Моя переменная 2');
2020
*
2121
* Нужно подключить этот файл в init.php
2222
* include 'BitrixDebugger/initializer.php';
2323
*
2424
*/
25-
use Bitrix\Main\Page\Asset;
26-
27-
if (!empty($_SERVER['DOCUMENT_ROOT'])) {
28-
29-
$ggrachDebuggerRootPath = str_replace($_SERVER['DOCUMENT_ROOT'], '', __DIR__);
30-
31-
\Bitrix\Main\Loader::registerAutoLoadClasses(null, [
32-
"\GGrach\BitrixDebugger\Debugger\Debugger" => $ggrachDebuggerRootPath . "/src/BitrixDebugger/Debugger/Debugger.php",
33-
"\GGrach\BitrixDebugger\Debugger\DebuggerShowModable" => $ggrachDebuggerRootPath . "/src/BitrixDebugger/Debugger/DebuggerShowModable.php",
34-
"\GGrach\BitrixDebugger\Contract\ShowModableContract" => $ggrachDebuggerRootPath . "/src/BitrixDebugger/Contract/ShowModableContract.php",
35-
"\GGrach\BitrixDebugger\Configurator\DebuggerConfigurator" => $ggrachDebuggerRootPath . "/src/BitrixDebugger/Configurator/DebuggerConfigurator.php",
36-
"\GGrach\BitrixDebugger\Configurator\DebugBarConfigurator" => $ggrachDebuggerRootPath . "/src/BitrixDebugger/Configurator/DebugBarConfigurator.php",
37-
"\GGrach\BitrixDebugger\Cache\RuntimeCache" => $ggrachDebuggerRootPath . "/src/BitrixDebugger/Cache/RuntimeCache.php",
38-
"\GGrach\BitrixDebugger\Validator\ShowModeDebuggerValidator" => $ggrachDebuggerRootPath . "/src/BitrixDebugger/Validator/ShowModeDebuggerValidator.php",
39-
"\GGrach\BitrixDebugger\Representer\DebugBarRepresenter" => $ggrachDebuggerRootPath . "/src/BitrixDebugger/Representer/DebugBarRepresenter.php",
40-
"\GGrach\Writer\FileWriter" => $ggrachDebuggerRootPath . "/src/Writer/FileWriter.php",
41-
"\GGrach\Writer\Contract\WritableContract" => $ggrachDebuggerRootPath . "/src/Writer/Contract/WritableContract.php"
42-
]);
43-
44-
$ggrachDebuggerConfigurator = new \GGrach\BitrixDebugger\Configurator\DebuggerConfigurator();
45-
$ggrachDebugBarConfigurator = new \GGrach\BitrixDebugger\Configurator\DebugBarConfigurator();
46-
47-
$ggrachDebuggerConfigurator->setLogPath('error', __DIR__ . '/logs/error.log');
48-
$ggrachDebuggerConfigurator->setLogPath('warning', __DIR__ . '/logs/warning.log');
49-
$ggrachDebuggerConfigurator->setLogPath('success', __DIR__ . '/logs/success.log');
50-
$ggrachDebuggerConfigurator->setLogPath('notice', __DIR__ . '/logs/notice.log');
51-
52-
global $GD;
53-
$GD = new \GGrach\BitrixDebugger\Debugger\Debugger($ggrachDebuggerConfigurator, $ggrachDebugBarConfigurator);
54-
55-
/*
56-
* code - отображать дебаг-данные в коде
57-
* debug_bar - отображать дебаг-данные в debug_bar
58-
*/
59-
$GD->setShowModes(['code', 'debug_bar']);
60-
61-
function GD() {
62-
global $GD;
63-
return $GD;
64-
}
65-
66-
if (\GGrach\BitrixDebugger\Validator\ShowModeDebuggerValidator::needShowInDebugBar($GD)) {
67-
68-
Asset::getInstance()->addJs($ggrachDebuggerRootPath . "/assets/DebugBar/js/initializer.js");
69-
Asset::getInstance()->addCss($ggrachDebuggerRootPath . '/assets/DebugBar/themes/general.css');
70-
Asset::getInstance()->addCss($ggrachDebuggerRootPath . '/assets/DebugBar/themes/' . $ggrachDebugBarConfigurator->getColorTheme() . '/theme.css');
71-
72-
include 'functions.php';
73-
74-
include 'events.php';
75-
}
25+
if (\php_sapi_name() === 'cli') {
26+
include 'initializers/cli.php';
27+
} else {
28+
include 'initializers/server.php';
7629
}

initializers/cli.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<?
2+
// Укажите ваш DOCUMENT_ROOT
3+
$_SERVER['DOCUMENT_ROOT'] = '/home/c/cq01452/public_html';
4+
5+
if (!empty($_SERVER['DOCUMENT_ROOT'])) {
6+
7+
$_SERVER['DOCUMENT_ROOT'] = rtrim($_SERVER['DOCUMENT_ROOT'], '/');
8+
9+
include 'server.php';
10+
}

initializers/server.php

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
<?
2+
3+
use Bitrix\Main\Page\Asset;
4+
5+
$ggrachDebuggerRootPath = str_replace($_SERVER['DOCUMENT_ROOT'], '', __DIR__ . '/..');
6+
$ggrachPathLogFolder = \realpath('.'.$ggrachDebuggerRootPath.'/logs');
7+
8+
\Bitrix\Main\Loader::registerAutoLoadClasses(null, [
9+
"\GGrach\BitrixDebugger\Debugger\Debugger" => $ggrachDebuggerRootPath . "/src/BitrixDebugger/Debugger/Debugger.php",
10+
"\GGrach\BitrixDebugger\Debugger\DebuggerShowModable" => $ggrachDebuggerRootPath . "/src/BitrixDebugger/Debugger/DebuggerShowModable.php",
11+
"\GGrach\BitrixDebugger\Contract\ShowModableContract" => $ggrachDebuggerRootPath . "/src/BitrixDebugger/Contract/ShowModableContract.php",
12+
"\GGrach\BitrixDebugger\Configurator\DebuggerConfigurator" => $ggrachDebuggerRootPath . "/src/BitrixDebugger/Configurator/DebuggerConfigurator.php",
13+
"\GGrach\BitrixDebugger\Configurator\DebugBarConfigurator" => $ggrachDebuggerRootPath . "/src/BitrixDebugger/Configurator/DebugBarConfigurator.php",
14+
"\GGrach\BitrixDebugger\Cache\RuntimeCache" => $ggrachDebuggerRootPath . "/src/BitrixDebugger/Cache/RuntimeCache.php",
15+
"\GGrach\BitrixDebugger\Validator\ShowModeDebuggerValidator" => $ggrachDebuggerRootPath . "/src/BitrixDebugger/Validator/ShowModeDebuggerValidator.php",
16+
"\GGrach\BitrixDebugger\Representer\DebugBarRepresenter" => $ggrachDebuggerRootPath . "/src/BitrixDebugger/Representer/DebugBarRepresenter.php",
17+
"\GGrach\Writer\FileWriter" => $ggrachDebuggerRootPath . "/src/Writer/FileWriter.php",
18+
"\GGrach\Writer\Contract\WritableContract" => $ggrachDebuggerRootPath . "/src/Writer/Contract/WritableContract.php",
19+
"\GGrach\BitrixDebugger\Events\OnEndBufferContent" => $ggrachDebuggerRootPath . "/src/BitrixDebugger/Events/OnEndBufferContent.php"
20+
]);
21+
22+
$ggrachDebuggerConfigurator = new \GGrach\BitrixDebugger\Configurator\DebuggerConfigurator();
23+
$ggrachDebugBarConfigurator = new \GGrach\BitrixDebugger\Configurator\DebugBarConfigurator();
24+
25+
$ggrachDebuggerConfigurator->setLogPath('error', $ggrachPathLogFolder . '/error.log');
26+
$ggrachDebuggerConfigurator->setLogPath('warning', $ggrachPathLogFolder . '/warning.log');
27+
$ggrachDebuggerConfigurator->setLogPath('success', $ggrachPathLogFolder . '/success.log');
28+
$ggrachDebuggerConfigurator->setLogPath('notice', $ggrachPathLogFolder . '/notice.log');
29+
30+
$GLOBALS["DD"] = new \GGrach\BitrixDebugger\Debugger\Debugger($ggrachDebuggerConfigurator, $ggrachDebugBarConfigurator);
31+
32+
/*
33+
* code - отображать дебаг-данные в коде
34+
* debug_bar - отображать дебаг-данные в debug_bar
35+
*/
36+
$GLOBALS["DD"]->setShowModes(['debug_bar']);
37+
38+
function DD() {
39+
return $GLOBALS["DD"];
40+
}
41+
42+
if (\GGrach\BitrixDebugger\Validator\ShowModeDebuggerValidator::needShowInDebugBar($GLOBALS["DD"])) {
43+
44+
Asset::getInstance()->addJs($ggrachDebuggerRootPath . "/assets/DebugBar/js/initializer.js");
45+
Asset::getInstance()->addCss($ggrachDebuggerRootPath . '/assets/DebugBar/css/themes/general.css');
46+
Asset::getInstance()->addCss($ggrachDebuggerRootPath . '/assets/DebugBar/css/themes/' . $ggrachDebugBarConfigurator->getColorTheme() . '/theme.css');
47+
48+
include __DIR__.'/../functions.php';
49+
include __DIR__.'/../events.php';
50+
}

phpunit.xml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!--Bootstrap указываем относительно папки local/php_interface/BitrixDebugger чтобы выйти в DOCUMENT_ROOT-->
3+
<phpunit bootstrap="bitrix/modules/main/include/prolog_before.php">
4+
<testsuites>
5+
<testsuite name="Notice raw">
6+
<file>../../../../NoticeRawTest.php</file>
7+
</testsuite>
8+
</testsuites>
9+
</phpunit>

0 commit comments

Comments
 (0)