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

Commit 76364bd

Browse files
authored
Merge pull request #5 from ggrachdev/dev
0.03
2 parents f2f1387 + c1ff030 commit 76364bd

File tree

17 files changed

+422
-116
lines changed

17 files changed

+422
-116
lines changed

composer.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@
1010
"autoload": {
1111
"psr-4": {
1212
"GGrach\\BitrixDebugger\\": "src/BitrixDebugger",
13-
"GGrach\\Writer\\": "src/Writer"
13+
"GGrach\\Writer\\": "src/Writer",
14+
"GGrach\\Filtrator\\": "src/Filtrator"
1415
}
1516
},
1617
"require": {}

initializer.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
/**
44
* https://github.com/ggrachdev/BitrixDebugger
55
6-
* @version 0.0.4 beta
6+
* @version 0.0.5 beta
77
*
88
* Пример дебага:
99
*
@@ -22,6 +22,9 @@
2222
* include 'BitrixDebugger/initializer.php';
2323
*
2424
*/
25+
26+
const GGRACH_DEBUG_BAR_TYPE_INCLUDE = 'initializer';
27+
2528
if (\php_sapi_name() === 'cli') {
2629
include 'initializers/cli.php';
2730
} else {

initializers/server.php

Lines changed: 1 addition & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -1,64 +1,2 @@
11
<?
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 . "/module/ggrachdev.debugbar/classes/general/BitrixDebugger/Debugger/Debugger.php",
10-
"\GGrach\BitrixDebugger\Debugger\NoticeDebugger" => $ggrachDebuggerRootPath . "/module/ggrachdev.debugbar/classes/general/BitrixDebugger/Debugger/NoticeDebugger.php",
11-
"\GGrach\BitrixDebugger\Debugger\LogFileDebugger" => $ggrachDebuggerRootPath . "/module/ggrachdev.debugbar/classes/general/BitrixDebugger/Debugger/LogFileDebugger.php",
12-
"\GGrach\BitrixDebugger\Debugger\ConfigurationDebugger" => $ggrachDebuggerRootPath . "/module/ggrachdev.debugbar/classes/general/BitrixDebugger/Debugger/ConfigurationDebugger.php",
13-
"\GGrach\BitrixDebugger\Contract\ShowModableContract" => $ggrachDebuggerRootPath . "/module/ggrachdev.debugbar/classes/general/BitrixDebugger/Contract/ShowModableContract.php",
14-
"\GGrach\BitrixDebugger\Configurator\DebuggerConfigurator" => $ggrachDebuggerRootPath . "/module/ggrachdev.debugbar/classes/general/BitrixDebugger/Configurator/DebuggerConfigurator.php",
15-
"\GGrach\BitrixDebugger\Configurator\DebugBarConfigurator" => $ggrachDebuggerRootPath . "/module/ggrachdev.debugbar/classes/general/BitrixDebugger/Configurator/DebugBarConfigurator.php",
16-
"\GGrach\BitrixDebugger\Cache\RuntimeCache" => $ggrachDebuggerRootPath . "/module/ggrachdev.debugbar/classes/general/BitrixDebugger/Cache/RuntimeCache.php",
17-
"\GGrach\BitrixDebugger\Validator\ShowModeDebuggerValidator" => $ggrachDebuggerRootPath . "/module/ggrachdev.debugbar/classes/general/BitrixDebugger/Validator/ShowModeDebuggerValidator.php",
18-
"\GGrach\BitrixDebugger\Representer\DebugBarRepresenter" => $ggrachDebuggerRootPath . "/module/ggrachdev.debugbar/classes/general/BitrixDebugger/Representer/DebugBarRepresenter.php",
19-
"\GGrach\Writer\FileWriter" => $ggrachDebuggerRootPath . "/module/ggrachdev.debugbar/classes/general/Writer/FileWriter.php",
20-
"\GGrach\Writer\Contract\WritableContract" => $ggrachDebuggerRootPath . "/module/ggrachdev.debugbar/classes/general/Writer/Contract/WritableContract.php",
21-
"\GGrach\BitrixDebugger\Events\OnEndBufferContent" => $ggrachDebuggerRootPath . "/module/ggrachdev.debugbar/classes/general/BitrixDebugger/Events/OnEndBufferContent.php"
22-
]);
23-
24-
$ggrachDebuggerConfigurator = new \GGrach\BitrixDebugger\Configurator\DebuggerConfigurator();
25-
$ggrachDebugBarConfigurator = new \GGrach\BitrixDebugger\Configurator\DebugBarConfigurator();
26-
27-
$ggrachDebuggerConfigurator->setLogPath('error', $ggrachPathLogFolder . '/error.log')
28-
->setLogPath('warning', $ggrachPathLogFolder . '/warning.log')
29-
->setLogPath('success', $ggrachPathLogFolder . '/success.log')
30-
->setLogPath('notice', $ggrachPathLogFolder . '/notice.log');
31-
32-
$GLOBALS["DD"] = new \GGrach\BitrixDebugger\Debugger\Debugger($ggrachDebuggerConfigurator, $ggrachDebugBarConfigurator);
33-
34-
/*
35-
* code - отображать дебаг-данные в коде
36-
* debug_bar - отображать дебаг-данные в debug_bar
37-
*/
38-
$GLOBALS["DD"]->getConfiguratorDebugger()->setShowModes(['debug_bar']);
39-
40-
function DD(...$data) {
41-
if (!empty($data)) {
42-
foreach ($data as $item) {
43-
$GLOBALS["DD"]->notice($item);
44-
}
45-
}
46-
47-
return $GLOBALS["DD"];
48-
}
49-
50-
if (\GGrach\BitrixDebugger\Validator\ShowModeDebuggerValidator::needShowInDebugBar(DD()->getConfiguratorDebugger())) {
51-
52-
Asset::getInstance()->addJs(
53-
$ggrachDebuggerRootPath . '/module/ggrachdev.debugbar/install/js/initializer.js'
54-
);
55-
Asset::getInstance()->addCss(
56-
$ggrachDebuggerRootPath . '/module/ggrachdev.debugbar/install/css/general.css'
57-
);
58-
Asset::getInstance()->addCss(
59-
$ggrachDebuggerRootPath . '/module/ggrachdev.debugbar/install/css/' . $ggrachDebugBarConfigurator->getColorTheme() . '/theme.css'
60-
);
61-
62-
include __DIR__ . '/../module/ggrachdev.debugbar/functions.php';
63-
include __DIR__ . '/../module/ggrachdev.debugbar/events.php';
64-
}
2+
include __DIR__ . '/../module/ggrachdev.debugbar/include.php';

module/ggrachdev.debugbar/classes/general/BitrixDebugger/Debugger/Debugger.php

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44

55
use GGrach\BitrixDebugger\Configurator\DebuggerConfigurator;
66
use GGrach\BitrixDebugger\Configurator\DebugBarConfigurator;
7+
use GGrach\Filtrator\FiltratorContract;
8+
use GGrach\Filtrator\Filtrator;
79

810
/**
911
* Ответственность: создание полноценного объекта, который позволит осуществлять все возможные операции через текучий интерфейс
@@ -12,7 +14,7 @@
1214
*/
1315
class Debugger extends LogFileDebugger {
1416

15-
public function __construct($debuggerConfigurator = null, $debugBarConfigurator = null) {
17+
public function __construct($debuggerConfigurator = null, $debugBarConfigurator = null, $filtrator = null) {
1618
if ($debuggerConfigurator === null) {
1719
$this->setConfiguratorDebugger(new DebuggerConfigurator());
1820
} elseif ($debuggerConfigurator instanceof DebuggerConfigurator) {
@@ -24,6 +26,12 @@ public function __construct($debuggerConfigurator = null, $debugBarConfigurator
2426
} elseif ($debugBarConfigurator instanceof DebugBarConfigurator) {
2527
$this->setConfiguratorDebugBar($debugBarConfigurator);
2628
}
29+
30+
if ($filtrator === null) {
31+
$this->setFiltrator(new Filtrator());
32+
} elseif ($filtrator instanceof FiltratorContract) {
33+
$this->setFiltrator($filtrator);
34+
}
2735
}
2836

2937
}
Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
<?php
2+
3+
namespace GGrach\BitrixDebugger\Debugger;
4+
5+
use GGrach\Filtrator\FiltratorContract;
6+
7+
/**
8+
* Ответственность: фильтрация входящих данных для дебага
9+
*
10+
* @author ggrachdev
11+
*/
12+
class FilterDebugger extends ConfigurationDebugger {
13+
14+
/**
15+
* @var FiltratorContract
16+
*/
17+
protected $filtrator;
18+
19+
/**
20+
* @var bool Не нужно сбрасывать фильтр после каждой операции логирования?
21+
*/
22+
protected $isFreezedFilter = false;
23+
24+
public function getFiltrator(): FiltratorContract {
25+
return $this->filtrator;
26+
}
27+
28+
public function setFiltrator(FiltratorContract $filtrator): self {
29+
$this->filtrator = $filtrator;
30+
return $this;
31+
}
32+
33+
public function resetFilter(): self {
34+
if (!$this->isFreezedFilter()) {
35+
$this->getFiltrator()->clearFilters();
36+
}
37+
return $this;
38+
}
39+
40+
public function isFreezedFilter(): bool {
41+
return $this->isFreezedFilter === true;
42+
}
43+
44+
public function unfreezeFilter(): self {
45+
$this->isFreezedFilter = false;
46+
return $this;
47+
}
48+
49+
public function freezeFilter(): self {
50+
$this->isFreezedFilter = true;
51+
return $this;
52+
}
53+
54+
public function filtrateItem($itemData) {
55+
return $this->getFiltrator()->filtrate($itemData);
56+
}
57+
58+
public function first(): self {
59+
$this->getFiltrator()->addFilter('first');
60+
return $this;
61+
}
62+
63+
public function last(): self {
64+
$this->getFiltrator()->addFilter('last');
65+
return $this;
66+
}
67+
68+
public function keys(array $availableKeys = []): self {
69+
$this->getFiltrator()->addFilter('keys', [
70+
'keys' => $availableKeys
71+
]);
72+
return $this;
73+
}
74+
75+
public function limit(int $limit = 10): self {
76+
$this->getFiltrator()->addFilter('limit', [
77+
'count' => $limit
78+
]);
79+
return $this;
80+
}
81+
82+
}

module/ggrachdev.debugbar/classes/general/BitrixDebugger/Debugger/LogFileDebugger.php

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -48,19 +48,27 @@ public function logRaw($type, ...$item) {
4848
}
4949

5050
public function noticeLog(...$item) {
51-
return $this->logRaw('notice', $item);
51+
$this->logRaw('notice', $item);
52+
$this->resetFilter();
53+
return $this;
5254
}
5355

5456
public function errorLog(...$item) {
55-
return $this->logRaw('error', $item);
57+
$this->logRaw('error', $item);
58+
$this->resetFilter();
59+
return $this;
5660
}
5761

5862
public function warningLog(...$item) {
59-
return $this->logRaw('warning', $item);
63+
$this->logRaw('warning', $item);
64+
$this->resetFilter();
65+
return $this;
6066
}
6167

6268
public function successLog(...$item) {
63-
return $this->logRaw('success', $item);
69+
$this->logRaw('success', $item);
70+
$this->resetFilter();
71+
return $this;
6472
}
6573

6674
}

module/ggrachdev.debugbar/classes/general/BitrixDebugger/Debugger/NoticeDebugger.php

Lines changed: 25 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,24 +9,32 @@
99
*
1010
* @author ggrachdev
1111
*/
12-
class NoticeDebugger extends ConfigurationDebugger {
12+
class NoticeDebugger extends FilterDebugger {
1313

1414
protected $log = [];
1515

1616
public function notice(...$item) {
17-
return $this->noticeRaw('notice', $item);
17+
$this->noticeRaw('notice', $item);
18+
$this->resetFilter();
19+
return $this;
1820
}
1921

2022
public function error(...$item) {
21-
return $this->noticeRaw('error', $item);
23+
$this->noticeRaw('error', $item);
24+
$this->resetFilter();
25+
return $this;
2226
}
2327

2428
public function warning(...$item) {
25-
return $this->noticeRaw('warning', $item);
29+
$this->noticeRaw('warning', $item);
30+
$this->resetFilter();
31+
return $this;
2632
}
2733

2834
public function success(...$item) {
29-
return $this->noticeRaw('success', $item);
35+
$this->noticeRaw('success', $item);
36+
$this->resetFilter();
37+
return $this;
3038
}
3139

3240
/**
@@ -115,14 +123,22 @@ public function getLog(bool $needAddSystemData = false): array {
115123
/**
116124
* Кастомизированное уведомление
117125
*
118-
* @param type $typeNotice
126+
* @param string $typeNotice
119127
* @param type $item
120128
*/
121-
public function debug($typeNotice, ...$item) {
122-
return $this->noticeRaw($typeNotice, $item);
129+
public function debug(string $typeNotice, ...$item) {
130+
$this->noticeRaw($typeNotice, $item);
131+
$this->resetFilter();
132+
return $this;
123133
}
124134

125-
protected function noticeRaw(string $type, $arLogItems) {
135+
protected function noticeRaw(string $type, array $arLogItems) {
136+
137+
if(!empty($arLogItems)) {
138+
foreach ($arLogItems as &$item) {
139+
$item = $this->filtrateItem($item);
140+
}
141+
}
126142

127143
if (ShowModeDebuggerValidator::needShowInDebugBar($this->getConfiguratorDebugger())) {
128144

module/ggrachdev.debugbar/classes/general/BitrixDebugger/Representer/DebugBarRepresenter.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,11 @@ public static function render(Debugger $debugger): string {
9696

9797
self::addViewInRightSlot('<a target="_blank" href="/bitrix/admin/site_edit.php?LID=' . \SITE_ID . '&lang=ru" class="ggrach__debug_bar__right__item type-notice-success" title="Текущая страница">' . SITE_CHARSET . '</a>');
9898

99-
$view = '<section class="ggrach__overlay" style="display: none;"></section><section class="ggrach__debug_bar">';
99+
$debugBarIsClosed = $_COOKIE['ggrach_debug_bar_is_close'] == 'true';
100+
101+
self::addViewInRightSlot('<a href="javascript:void(0);" data-click="toggle_debug_bar" class="ggrach__debug_bar__right__item ggrach__debug_bar__right__item_close ggrach-debug-bar-color-black" title="Скрыть / Раскрыть фильтр">&#215;</a>');
102+
103+
$view = '<section class="ggrach__overlay" style="display: none;"></section><section class="ggrach__debug_bar '.($debugBarIsClosed ? 'hide-debug-bar' : '').'">';
100104

101105
$view .= self::renderLeftView();
102106
$view .= self::renderRightView();

0 commit comments

Comments
 (0)