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

Commit aedf90d

Browse files
committed
Улучшен скелет noticeRaw в Debugger'e
1 parent 403d973 commit aedf90d

8 files changed

Lines changed: 166 additions & 79 deletions

File tree

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
/nbproject/
2-
/vendor/
2+
/vendor/
3+
/todo.txt

src/BitrixDebugger/Configurator/DebuggerConfigurator.php

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,14 +37,30 @@ public function setLogPath(string $logType, string $pathFile): self {
3737
}
3838

3939
/**
40-
* Получить пути всех-лог файлов
40+
* Получить пути всех лог-типов
4141
*
42-
* @return type
42+
* @return array
4343
*/
44-
public function getLogPaths() {
44+
public function getLogPaths(): array {
4545
return $this->logPaths;
4646
}
4747

48+
/**
49+
* Получить путь лог-типа
50+
*
51+
* @return string | null
52+
*/
53+
public function getLogPath(string $typeLog) {
54+
if(\array_key_exists($typeLog, $this->getLogPaths()))
55+
{
56+
return $this->getLogPaths()[$typeLog];
57+
}
58+
else
59+
{
60+
return null;
61+
}
62+
}
63+
4864
public function getLogChunkDelimeter() {
4965
return $this->logChunkDelimeter;
5066
}

src/BitrixDebugger/Contract/ShowModableContract.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,4 +30,12 @@ public function getShowModesEnum(): array;
3030
* @return bool Результат
3131
*/
3232
public function setShowModes(array $showModes): bool;
33+
34+
/**
35+
* Установить один режим отображения
36+
*
37+
* @param string $showMode
38+
* @return bool Результат
39+
*/
40+
public function setShowMode(string $showMode): bool;
3341
}

src/BitrixDebugger/Debugger/Debugger.php

Lines changed: 44 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -5,77 +5,60 @@
55
use GGrach\BitrixDebugger\Configurator\DebuggerConfigurator;
66
use GGrach\BitrixDebugger\Configurator\DebugBarConfigurator;
77
use GGrach\BitrixDebugger\Contract\ShowModableContract;
8-
8+
use GGrach\BitrixDebugger\Validator\ShowModeDebuggerValidator;
9+
use GGrach\BitrixDebugger\Debugger\DebuggerShowModable;
910

1011
/**
1112
* Description of Debugger
1213
*
1314
* @author ggrachdev
1415
* @version 0.01
1516
*/
16-
class Debugger implements ShowModableContract {
17-
18-
public function __construct($debuggerConfigurator = null, $debugBarConfigurator = null) {
19-
if ($debuggerConfigurator === null) {
20-
$this->configuratorDebugger = new DebuggerConfigurator();
21-
} elseif ($debuggerConfigurator instanceof DebuggerConfigurator) {
22-
$this->configuratorDebugger = $debuggerConfigurator;
23-
}
24-
25-
if ($debugBarConfigurator === null) {
26-
$this->configuratorDebugBar = new DebugBarConfigurator();
27-
} elseif ($debugBarConfigurator instanceof DebugBarConfigurator) {
28-
$this->configuratorDebugBar = $debugBarConfigurator;
29-
}
30-
}
17+
class Debugger extends DebuggerShowModable implements ShowModableContract {
3118

3219
/**
3320
*
3421
* @var DebuggerConfigurator
3522
*/
36-
private $configuratorDebugger;
23+
protected $configuratorDebugger;
3724

3825
/**
3926
*
4027
* @var DebugBarConfigurator
4128
*/
42-
private $configuratorDebugBar;
29+
protected $configuratorDebugBar;
4330

4431
/**
4532
* Лог
4633
*
4734
* @var array
4835
*/
49-
private $log = [];
36+
protected $log = [];
5037

5138
/**
5239
* a - показывать только для администратора
5340
* d - показывать только в дебаг-баре
5441
*
5542
* @var string
5643
*/
57-
private $options = 'ad';
44+
protected $options = 'ad';
5845

59-
/**
60-
* Где показывать
61-
*
62-
* everywhere - и в дебаг-баре и в коде и залогировать
63-
* code - в коде
64-
* debug_bar - в дебаг-баре
65-
* log - залогировать
66-
* no - не показывать нигде
67-
*
68-
* @var array
69-
*/
70-
protected $showModes = ['everywhere'];
71-
72-
public function getShowModes()
73-
{
74-
return $this->showModes;
46+
public function __construct($debuggerConfigurator = null, $debugBarConfigurator = null) {
47+
if ($debuggerConfigurator === null) {
48+
$this->configuratorDebugger = new DebuggerConfigurator();
49+
} elseif ($debuggerConfigurator instanceof DebuggerConfigurator) {
50+
$this->configuratorDebugger = $debuggerConfigurator;
51+
}
52+
53+
if ($debugBarConfigurator === null) {
54+
$this->configuratorDebugBar = new DebugBarConfigurator();
55+
} elseif ($debugBarConfigurator instanceof DebugBarConfigurator) {
56+
$this->configuratorDebugBar = $debugBarConfigurator;
57+
}
7558
}
7659

77-
public function options($options) {
78-
60+
public function options(array $options) {
61+
$this->options = $options;
7962
}
8063

8164
public function notice(...$item) {
@@ -90,21 +73,33 @@ public function success(...$item) {
9073
$this->noticeRaw('success', $item);
9174
}
9275

93-
public function noticeRaw(string $type, $items) {
76+
/**
77+
* Кастомизированное уведомление
78+
*
79+
* @param type $typeNotice
80+
* @param type $item
81+
*/
82+
public function debug($typeNotice, ...$item) {
83+
$this->noticeRaw($typeNotice, $item);
84+
}
85+
86+
protected function noticeRaw(string $type, $items) {
9487

95-
if ($this->needShowInDebugBar()) {
96-
$this->log[] = $items;
88+
if (ShowModeDebuggerValidator::needShowInDebugBar($this)) {
89+
$this->log = array_merge($this->log, $items);
9790
}
98-
}
9991

100-
public function getShowModesEnum(): array {
101-
// @todo
102-
return [];
103-
}
92+
if (ShowModeDebuggerValidator::needShowInCode($this)) {
93+
94+
}
10495

105-
public function setShowModes(array $showModes): bool {
106-
// @todo
107-
return true;
96+
if (ShowModeDebuggerValidator::needWriteInLog($this)) {
97+
$logFile = $this->configuratorDebugger->getLogPath($type);
98+
99+
if ($logFile) {
100+
101+
}
102+
}
108103
}
109104

110105
}
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
<?php
2+
3+
namespace GGrach\BitrixDebugger\Debugger;
4+
5+
use GGrach\BitrixDebugger\Configurator\DebuggerConfigurator;
6+
use GGrach\BitrixDebugger\Configurator\DebugBarConfigurator;
7+
use GGrach\BitrixDebugger\Contract\ShowModableContract;
8+
use GGrach\BitrixDebugger\Validator\ShowModeDebuggerValidator;
9+
10+
/**
11+
* Description of Debugger
12+
*
13+
* @author ggrachdev
14+
* @version 0.01
15+
*/
16+
class DebuggerShowModable implements ShowModableContract {
17+
18+
/**
19+
* Где показывать
20+
*
21+
* code - в коде
22+
* debug_bar - в дебаг-баре
23+
* log - в логе
24+
*
25+
* @var array
26+
*/
27+
protected $showModes = ['code', 'debug_bar'];
28+
29+
public function getShowModes() {
30+
return $this->showModes;
31+
}
32+
33+
public function getShowModesEnum(): array {
34+
return ['code', 'debug_bar', 'log'];
35+
}
36+
37+
public function setShowModes(array $showModes): bool {
38+
$result = true;
39+
40+
if (!empty($showModes)) {
41+
42+
$avaliableModes = $this->getShowModesEnum();
43+
44+
// @todo array_udiff
45+
foreach ($showModes as $mode) {
46+
if (!\in_array($mode, $avaliableModes)) {
47+
$result = false;
48+
break;
49+
}
50+
}
51+
52+
if ($result) {
53+
$this->showModes = $showModes;
54+
}
55+
} else {
56+
$result = false;
57+
}
58+
59+
return $result;
60+
}
61+
62+
public function setShowMode(string $showMode): bool {
63+
return $this->setShowModes([$showMode]);
64+
}
65+
66+
}

src/BitrixDebugger/Facade/.gitkeep

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
<?php
2+
3+
namespace GGrach\BitrixDebugger\Validator;
4+
5+
use GGrach\BitrixDebugger\Contract\ShowModableContract;
6+
7+
/**
8+
* Description of ShowModeDebuggerValidator
9+
*
10+
* @author ggrachdev
11+
*/
12+
class ShowModeDebuggerValidator {
13+
14+
public static function needShowInDebugBar(ShowModableContract $debugger) {
15+
return in_array('debug_bar', $debugger->getShowModes());
16+
}
17+
18+
public static function needShowInCode(ShowModableContract $debugger) {
19+
return in_array('code', $debugger->getShowModes());
20+
}
21+
22+
public static function needWriteInLog(ShowModableContract $debugger) {
23+
return in_array('log', $debugger->getShowModes());
24+
}
25+
26+
}

src/BitrixDebugger/Validator/ShowModeValidator.php

Lines changed: 0 additions & 26 deletions
This file was deleted.

0 commit comments

Comments
 (0)