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

Commit e346c52

Browse files
authored
Merge pull request #10 from ggrachdev/dev
0.0.8
2 parents f119712 + 3aa1960 commit e346c52

File tree

13 files changed

+110
-129
lines changed

13 files changed

+110
-129
lines changed

ggrachdev.debugbar/classes/general/BitrixDebugger/Configurator/DebuggerConfigurator.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,14 @@
22

33
namespace GGrach\BitrixDebugger\Configurator;
44

5-
use \GGrach\BitrixDebugger\Contract\ShowModableContract;
5+
use \GGrach\BitrixDebugger\Contract\IShowModable;
66

77
/**
88
* Description of DebugConfigurator
99
*
1010
* @author ggrachdev
1111
*/
12-
class DebuggerConfigurator implements ShowModableContract {
12+
class DebuggerConfigurator implements IShowModable {
1313

1414
/**
1515
* Путь до лог файлов разного уровня
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
*
88
* @author ggrachdev
99
*/
10-
interface ShowModableContract {
10+
interface IShowModable {
1111

1212
/**
1313
* Получить режимы отображения установленные

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,11 @@
44

55
use GGrach\BitrixDebugger\Configurator\DebuggerConfigurator;
66
use GGrach\BitrixDebugger\Configurator\DebugBarConfigurator;
7-
use GGrach\Filtrator\FiltratorContract;
7+
use GGrach\Filtrator\IFiltrator;
88
use GGrach\Filtrator\Filtrator;
99

1010
/**
11-
* Ответственность: создание полноценного объекта, который позволит осуществлять все возможные операции через текучий интерфейс
11+
* Создание полноценного объекта, который позволит осуществлять все возможные операции через текучий интерфейс
1212
*
1313
* @author ggrachdev
1414
*/
@@ -29,7 +29,7 @@ public function __construct($debuggerConfigurator = null, $debugBarConfigurator
2929

3030
if ($filtrator === null) {
3131
$this->setFiltrator(new Filtrator());
32-
} elseif ($filtrator instanceof FiltratorContract) {
32+
} elseif ($filtrator instanceof IFiltrator) {
3333
$this->setFiltrator($filtrator);
3434
}
3535
}

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

Lines changed: 6 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
namespace GGrach\BitrixDebugger\Debugger;
44

5-
use GGrach\Filtrator\FiltratorContract;
5+
use GGrach\Filtrator\IFiltrator;
66

77
/**
88
* Ответственность: фильтрация входящих данных для дебага
@@ -12,7 +12,7 @@
1212
class FilterDebugger extends ConfigurationDebugger {
1313

1414
/**
15-
* @var FiltratorContract
15+
* @var IFiltrator
1616
*/
1717
protected $filtrator;
1818

@@ -31,7 +31,7 @@ class FilterDebugger extends ConfigurationDebugger {
3131
*/
3232
public function __call($name, $arguments) {
3333

34-
if($this->getFiltrator()->hasCustomFilter($name))
34+
if($this->getFiltrator()->hasFilter($name))
3535
{
3636
$this->getFiltrator()->addFilter($name, $arguments);
3737
}
@@ -43,16 +43,16 @@ public function __call($name, $arguments) {
4343
return $this;
4444
}
4545

46-
public function getFiltrator(): FiltratorContract {
46+
public function getFiltrator(): IFiltrator {
4747
return $this->filtrator;
4848
}
4949

5050
public function addFilter(string $nameMethod, callable $callback): self {
51-
$this->getFiltrator()->addCustomFilter($nameMethod, $callback);
51+
$this->getFiltrator()->addFilterRule($nameMethod, $callback);
5252
return $this;
5353
}
5454

55-
public function setFiltrator(FiltratorContract $filtrator): self {
55+
public function setFiltrator(IFiltrator $filtrator): self {
5656
$this->filtrator = $filtrator;
5757
return $this;
5858
}
@@ -82,28 +82,4 @@ public function filtrateItem($itemData) {
8282
return $this->getFiltrator()->filtrate($itemData);
8383
}
8484

85-
public function first(): self {
86-
$this->getFiltrator()->addFilter('first');
87-
return $this;
88-
}
89-
90-
public function last(): self {
91-
$this->getFiltrator()->addFilter('last');
92-
return $this;
93-
}
94-
95-
public function keys(array $availableKeys = []): self {
96-
$this->getFiltrator()->addFilter('keys', [
97-
'keys' => $availableKeys
98-
]);
99-
return $this;
100-
}
101-
102-
public function limit(int $limit = 10): self {
103-
$this->getFiltrator()->addFilter('limit', [
104-
'count' => $limit
105-
]);
106-
return $this;
107-
}
108-
10985
}

ggrachdev.debugbar/classes/general/BitrixDebugger/Validator/ShowModeDebuggerValidator.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
namespace GGrach\BitrixDebugger\Validator;
44

5-
use GGrach\BitrixDebugger\Contract\ShowModableContract;
5+
use GGrach\BitrixDebugger\Contract\IShowModable;
66

77
/**
88
* Проверка допустимых действий для режимов отображения
@@ -11,11 +11,11 @@
1111
*/
1212
class ShowModeDebuggerValidator {
1313

14-
public static function needShowInDebugBar(ShowModableContract $showModable) {
14+
public static function needShowInDebugBar(IShowModable $showModable) {
1515
return in_array('debug_bar', $showModable->getShowModes());
1616
}
1717

18-
public static function needShowInCode(ShowModableContract $showModable) {
18+
public static function needShowInCode(IShowModable $showModable) {
1919
global $USER;
2020
return in_array('code', $showModable->getShowModes()) && \is_object($USER) && $USER->IsAdmin();
2121
}

ggrachdev.debugbar/classes/general/Filtrator/Filtrator.php

Lines changed: 16 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,12 @@
22

33
namespace GGrach\Filtrator;
44

5-
use \GGrach\Filtrator\FiltratorContract;
5+
use \GGrach\Filtrator\IFiltrator;
66

77
/**
88
* @author ggrachdev
99
*/
10-
class Filtrator implements FiltratorContract {
11-
12-
public const FILTERS_NAME = [
13-
'limit', 'first', 'last', 'keys'
14-
];
10+
class Filtrator implements IFiltrator {
1511

1612
private $customFilters = [];
1713

@@ -22,91 +18,43 @@ class Filtrator implements FiltratorContract {
2218
*/
2319
protected $sequenceFilters;
2420

25-
public function addFilter(string $filterType, array $filterParams = []): void {
26-
if ($this->hasFilter($filterType) || $this->hasCustomFilter($filterType)) {
27-
$this->sequenceFilters[] = [
28-
'type' => $filterType,
29-
'params' => $filterParams
30-
];
31-
}
32-
}
33-
34-
public function filtrateItem(string $filterType, array $filterParams, $data) {
35-
switch ($filterType) {
36-
case 'limit':
37-
if (\is_array($data) && !empty($data)) {
38-
if (empty($filterParams['count']) || $filterParams['count'] < 1) {
39-
$filterParams['count'] = 10;
40-
}
41-
$data = array_slice($data, 0, $filterParams['count'], true);
42-
}
43-
break;
44-
case 'first':
45-
if (\is_array($data) && !empty($data)) {
46-
$data = array_shift($data);
47-
}
48-
break;
49-
case 'keys':
50-
if (\is_array($data) && !empty($data) && !empty($filterParams['keys'])) {
51-
$newData = [];
52-
53-
foreach ($data as $k => $v) {
54-
if (\in_array($k, $filterParams['keys'])) {
55-
$newData[$k] = $v;
56-
}
57-
}
58-
59-
$data = $newData;
60-
}
61-
break;
62-
case 'last':
63-
if (\is_array($data) && !empty($data)) {
64-
$data = array_pop($data);
65-
}
66-
break;
67-
}
68-
69-
return $data;
70-
}
71-
7221
public function clearFilters(): void {
7322
$this->sequenceFilters = [];
7423
}
7524

7625
public function filtrate($data) {
7726
if (!empty($this->sequenceFilters) && !empty($data)) {
7827
foreach ($this->sequenceFilters as $arFilter) {
79-
if($this->hasCustomFilter($arFilter['type']))
80-
{
81-
$data = $this->customFiltrateItem($arFilter['type'], $arFilter['params'], $data);
82-
}
83-
else {
84-
$data = $this->filtrateItem($arFilter['type'], $arFilter['params'], $data);
85-
}
28+
$data = $this->filtrateItem($arFilter['type'], $arFilter['params'], $data);
8629
}
8730
}
8831

8932
return $data;
9033
}
9134

35+
public function addFilter(string $filterType, array $filterParams = []): void {
36+
if ($this->hasFilter($filterType)) {
37+
$this->sequenceFilters[] = [
38+
'type' => $filterType,
39+
'params' => $filterParams
40+
];
41+
}
42+
}
43+
9244
public function hasFilter(string $filterType): bool {
93-
return \in_array($filterType, self::FILTERS_NAME);
45+
return \array_key_exists($filterType, $this->customFilters);
9446
}
9547

96-
public function addCustomFilter(string $filterName, callable $callback) {
97-
if (!$this->hasCustomFilter($filterName)) {
48+
public function addFilterRule(string $filterName, callable $callback): IFiltrator {
49+
if (!$this->hasFilter($filterName)) {
9850
$this->customFilters[$filterName] = $callback;
9951
}
10052

10153
return $this;
10254
}
10355

104-
public function customFiltrateItem(string $filterType, array $filterParams, $data) {
56+
public function filtrateItem(string $filterType, array $filterParams, $data) {
10557
return $this->customFilters[$filterType]($data, $filterParams);
10658
}
10759

108-
public function hasCustomFilter(string $filterName) {
109-
return \array_key_exists($filterName, $this->customFilters);
110-
}
111-
11260
}

ggrachdev.debugbar/classes/general/Filtrator/FiltratorContract.php renamed to ggrachdev.debugbar/classes/general/Filtrator/IFiltrator.php

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,24 +2,16 @@
22

33
namespace GGrach\Filtrator;
44

5-
/**
6-
*
7-
* @author ggrachdev
8-
*/
9-
interface FiltratorContract {
5+
interface IFiltrator {
106
public function filtrate($data);
117

12-
public function addCustomFilter(string $filterName, callable $callback);
8+
public function hasFilter(string $filterType): bool;
139

14-
public function hasCustomFilter(string $filterName);
10+
public function addFilterRule(string $filterName, callable $callback): self;
1511

16-
public function customFiltrateItem(string $filterType, array $filterParams, $data);
12+
public function addFilter(string $filterType, array $filterParams = []): void;
1713

1814
public function filtrateItem(string $filterType, array $filterParams, $data);
1915

20-
public function addFilter(string $filterType, array $filterParams): void;
21-
22-
public function hasFilter(string $filterType): bool;
23-
2416
public function clearFilters(): void;
2517
}

ggrachdev.debugbar/classes/general/Writer/Contract/WritableContract.php renamed to ggrachdev.debugbar/classes/general/Writer/Contract/IWritable.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
*
88
* @author ggrachdev
99
*/
10-
interface WritableContract {
10+
interface IWritable {
1111

1212
/**
1313
* Запись данных в ресурс

ggrachdev.debugbar/classes/general/Writer/FileWriter.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,14 @@
22

33
namespace GGrach\Writer;
44

5-
use GGrach\Writer\Contract\WritableContract;
5+
use GGrach\Writer\Contract\IWritable;
66

77
/**
88
* Запись данных в файл
99
*
1010
* @author ggrachdev
1111
*/
12-
class FileWriter implements WritableContract {
12+
class FileWriter implements IWritable {
1313

1414
/**
1515
* Запись данных в ресурс

ggrachdev.debugbar/filters.php

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
<?php
2+
3+
DD()->addFilter('values', function ($data, $filterParams) {
4+
if (\is_array($data)) {
5+
return \array_values($data);
6+
} else {
7+
return $data;
8+
}
9+
});
10+
11+
DD()->addFilter('limit', function ($data, $filterParams) {
12+
if (\is_array($data) && !empty($data)) {
13+
if (empty($filterParams[0]) || !\is_numeric($filterParams[0]) || $filterParams[0] < 1) {
14+
$count = 10;
15+
} else {
16+
$count = $filterParams[0];
17+
}
18+
$data = array_slice($data, 0, $count, true);
19+
}
20+
21+
return $data;
22+
});
23+
24+
DD()->addFilter('first', function ($data, $filterParams) {
25+
if (\is_array($data) && !empty($data)) {
26+
$data = array_shift($data);
27+
}
28+
29+
return $data;
30+
});
31+
32+
DD()->addFilter('keys', function ($data, $filterParams) {
33+
34+
if (
35+
!empty($data) &&
36+
is_array($data) &&
37+
!empty($filterParams[0]) &&
38+
\is_array($filterParams[0])
39+
) {
40+
$newData = [];
41+
42+
foreach ($data as $k => $v) {
43+
if (\in_array($k, $filterParams[0])) {
44+
$newData[$k] = $v;
45+
}
46+
}
47+
48+
$data = $newData;
49+
}
50+
51+
return $data;
52+
});
53+
54+
DD()->addFilter('last', function ($data, $filterParams) {
55+
if (\is_array($data) && !empty($data)) {
56+
$data = array_pop($data);
57+
}
58+
59+
return $data;
60+
});

0 commit comments

Comments
 (0)