diff --git a/ggrachdev.debugbar/classes/general/BitrixDebugger/Configurator/DebuggerConfigurator.php b/ggrachdev.debugbar/classes/general/BitrixDebugger/Configurator/DebuggerConfigurator.php index 0d94bd1..23eaf82 100644 --- a/ggrachdev.debugbar/classes/general/BitrixDebugger/Configurator/DebuggerConfigurator.php +++ b/ggrachdev.debugbar/classes/general/BitrixDebugger/Configurator/DebuggerConfigurator.php @@ -2,14 +2,14 @@ namespace GGrach\BitrixDebugger\Configurator; -use \GGrach\BitrixDebugger\Contract\ShowModableContract; +use \GGrach\BitrixDebugger\Contract\IShowModable; /** * Description of DebugConfigurator * * @author ggrachdev */ -class DebuggerConfigurator implements ShowModableContract { +class DebuggerConfigurator implements IShowModable { /** * Путь до лог файлов разного уровня diff --git a/ggrachdev.debugbar/classes/general/BitrixDebugger/Contract/ShowModableContract.php b/ggrachdev.debugbar/classes/general/BitrixDebugger/Contract/IShowModable.php similarity index 96% rename from ggrachdev.debugbar/classes/general/BitrixDebugger/Contract/ShowModableContract.php rename to ggrachdev.debugbar/classes/general/BitrixDebugger/Contract/IShowModable.php index b2e7b75..8be9b3f 100644 --- a/ggrachdev.debugbar/classes/general/BitrixDebugger/Contract/ShowModableContract.php +++ b/ggrachdev.debugbar/classes/general/BitrixDebugger/Contract/IShowModable.php @@ -7,7 +7,7 @@ * * @author ggrachdev */ -interface ShowModableContract { +interface IShowModable { /** * Получить режимы отображения установленные diff --git a/ggrachdev.debugbar/classes/general/BitrixDebugger/Debugger/Debugger.php b/ggrachdev.debugbar/classes/general/BitrixDebugger/Debugger/Debugger.php index 9332b17..d94793b 100644 --- a/ggrachdev.debugbar/classes/general/BitrixDebugger/Debugger/Debugger.php +++ b/ggrachdev.debugbar/classes/general/BitrixDebugger/Debugger/Debugger.php @@ -4,11 +4,11 @@ use GGrach\BitrixDebugger\Configurator\DebuggerConfigurator; use GGrach\BitrixDebugger\Configurator\DebugBarConfigurator; -use GGrach\Filtrator\FiltratorContract; +use GGrach\Filtrator\IFiltrator; use GGrach\Filtrator\Filtrator; /** - * Ответственность: создание полноценного объекта, который позволит осуществлять все возможные операции через текучий интерфейс + * Создание полноценного объекта, который позволит осуществлять все возможные операции через текучий интерфейс * * @author ggrachdev */ @@ -29,7 +29,7 @@ public function __construct($debuggerConfigurator = null, $debugBarConfigurator if ($filtrator === null) { $this->setFiltrator(new Filtrator()); - } elseif ($filtrator instanceof FiltratorContract) { + } elseif ($filtrator instanceof IFiltrator) { $this->setFiltrator($filtrator); } } diff --git a/ggrachdev.debugbar/classes/general/BitrixDebugger/Debugger/FilterDebugger.php b/ggrachdev.debugbar/classes/general/BitrixDebugger/Debugger/FilterDebugger.php index 474ad88..9f99ec6 100644 --- a/ggrachdev.debugbar/classes/general/BitrixDebugger/Debugger/FilterDebugger.php +++ b/ggrachdev.debugbar/classes/general/BitrixDebugger/Debugger/FilterDebugger.php @@ -2,7 +2,7 @@ namespace GGrach\BitrixDebugger\Debugger; -use GGrach\Filtrator\FiltratorContract; +use GGrach\Filtrator\IFiltrator; /** * Ответственность: фильтрация входящих данных для дебага @@ -12,7 +12,7 @@ class FilterDebugger extends ConfigurationDebugger { /** - * @var FiltratorContract + * @var IFiltrator */ protected $filtrator; @@ -31,7 +31,7 @@ class FilterDebugger extends ConfigurationDebugger { */ public function __call($name, $arguments) { - if($this->getFiltrator()->hasCustomFilter($name)) + if($this->getFiltrator()->hasFilter($name)) { $this->getFiltrator()->addFilter($name, $arguments); } @@ -43,16 +43,16 @@ public function __call($name, $arguments) { return $this; } - public function getFiltrator(): FiltratorContract { + public function getFiltrator(): IFiltrator { return $this->filtrator; } public function addFilter(string $nameMethod, callable $callback): self { - $this->getFiltrator()->addCustomFilter($nameMethod, $callback); + $this->getFiltrator()->addFilterRule($nameMethod, $callback); return $this; } - public function setFiltrator(FiltratorContract $filtrator): self { + public function setFiltrator(IFiltrator $filtrator): self { $this->filtrator = $filtrator; return $this; } @@ -82,28 +82,4 @@ public function filtrateItem($itemData) { return $this->getFiltrator()->filtrate($itemData); } - public function first(): self { - $this->getFiltrator()->addFilter('first'); - return $this; - } - - public function last(): self { - $this->getFiltrator()->addFilter('last'); - return $this; - } - - public function keys(array $availableKeys = []): self { - $this->getFiltrator()->addFilter('keys', [ - 'keys' => $availableKeys - ]); - return $this; - } - - public function limit(int $limit = 10): self { - $this->getFiltrator()->addFilter('limit', [ - 'count' => $limit - ]); - return $this; - } - } diff --git a/ggrachdev.debugbar/classes/general/BitrixDebugger/Validator/ShowModeDebuggerValidator.php b/ggrachdev.debugbar/classes/general/BitrixDebugger/Validator/ShowModeDebuggerValidator.php index 19acd65..f728f3d 100644 --- a/ggrachdev.debugbar/classes/general/BitrixDebugger/Validator/ShowModeDebuggerValidator.php +++ b/ggrachdev.debugbar/classes/general/BitrixDebugger/Validator/ShowModeDebuggerValidator.php @@ -2,7 +2,7 @@ namespace GGrach\BitrixDebugger\Validator; -use GGrach\BitrixDebugger\Contract\ShowModableContract; +use GGrach\BitrixDebugger\Contract\IShowModable; /** * Проверка допустимых действий для режимов отображения @@ -11,11 +11,11 @@ */ class ShowModeDebuggerValidator { - public static function needShowInDebugBar(ShowModableContract $showModable) { + public static function needShowInDebugBar(IShowModable $showModable) { return in_array('debug_bar', $showModable->getShowModes()); } - public static function needShowInCode(ShowModableContract $showModable) { + public static function needShowInCode(IShowModable $showModable) { global $USER; return in_array('code', $showModable->getShowModes()) && \is_object($USER) && $USER->IsAdmin(); } diff --git a/ggrachdev.debugbar/classes/general/Filtrator/Filtrator.php b/ggrachdev.debugbar/classes/general/Filtrator/Filtrator.php index 1222d80..f8d06f6 100644 --- a/ggrachdev.debugbar/classes/general/Filtrator/Filtrator.php +++ b/ggrachdev.debugbar/classes/general/Filtrator/Filtrator.php @@ -2,16 +2,12 @@ namespace GGrach\Filtrator; -use \GGrach\Filtrator\FiltratorContract; +use \GGrach\Filtrator\IFiltrator; /** * @author ggrachdev */ -class Filtrator implements FiltratorContract { - - public const FILTERS_NAME = [ - 'limit', 'first', 'last', 'keys' - ]; +class Filtrator implements IFiltrator { private $customFilters = []; @@ -22,53 +18,6 @@ class Filtrator implements FiltratorContract { */ protected $sequenceFilters; - public function addFilter(string $filterType, array $filterParams = []): void { - if ($this->hasFilter($filterType) || $this->hasCustomFilter($filterType)) { - $this->sequenceFilters[] = [ - 'type' => $filterType, - 'params' => $filterParams - ]; - } - } - - public function filtrateItem(string $filterType, array $filterParams, $data) { - switch ($filterType) { - case 'limit': - if (\is_array($data) && !empty($data)) { - if (empty($filterParams['count']) || $filterParams['count'] < 1) { - $filterParams['count'] = 10; - } - $data = array_slice($data, 0, $filterParams['count'], true); - } - break; - case 'first': - if (\is_array($data) && !empty($data)) { - $data = array_shift($data); - } - break; - case 'keys': - if (\is_array($data) && !empty($data) && !empty($filterParams['keys'])) { - $newData = []; - - foreach ($data as $k => $v) { - if (\in_array($k, $filterParams['keys'])) { - $newData[$k] = $v; - } - } - - $data = $newData; - } - break; - case 'last': - if (\is_array($data) && !empty($data)) { - $data = array_pop($data); - } - break; - } - - return $data; - } - public function clearFilters(): void { $this->sequenceFilters = []; } @@ -76,37 +25,36 @@ public function clearFilters(): void { public function filtrate($data) { if (!empty($this->sequenceFilters) && !empty($data)) { foreach ($this->sequenceFilters as $arFilter) { - if($this->hasCustomFilter($arFilter['type'])) - { - $data = $this->customFiltrateItem($arFilter['type'], $arFilter['params'], $data); - } - else { - $data = $this->filtrateItem($arFilter['type'], $arFilter['params'], $data); - } + $data = $this->filtrateItem($arFilter['type'], $arFilter['params'], $data); } } return $data; } + public function addFilter(string $filterType, array $filterParams = []): void { + if ($this->hasFilter($filterType)) { + $this->sequenceFilters[] = [ + 'type' => $filterType, + 'params' => $filterParams + ]; + } + } + public function hasFilter(string $filterType): bool { - return \in_array($filterType, self::FILTERS_NAME); + return \array_key_exists($filterType, $this->customFilters); } - public function addCustomFilter(string $filterName, callable $callback) { - if (!$this->hasCustomFilter($filterName)) { + public function addFilterRule(string $filterName, callable $callback): IFiltrator { + if (!$this->hasFilter($filterName)) { $this->customFilters[$filterName] = $callback; } return $this; } - public function customFiltrateItem(string $filterType, array $filterParams, $data) { + public function filtrateItem(string $filterType, array $filterParams, $data) { return $this->customFilters[$filterType]($data, $filterParams); } - public function hasCustomFilter(string $filterName) { - return \array_key_exists($filterName, $this->customFilters); - } - } diff --git a/ggrachdev.debugbar/classes/general/Filtrator/FiltratorContract.php b/ggrachdev.debugbar/classes/general/Filtrator/IFiltrator.php similarity index 52% rename from ggrachdev.debugbar/classes/general/Filtrator/FiltratorContract.php rename to ggrachdev.debugbar/classes/general/Filtrator/IFiltrator.php index a8e0a04..0598758 100644 --- a/ggrachdev.debugbar/classes/general/Filtrator/FiltratorContract.php +++ b/ggrachdev.debugbar/classes/general/Filtrator/IFiltrator.php @@ -2,24 +2,16 @@ namespace GGrach\Filtrator; -/** - * - * @author ggrachdev - */ -interface FiltratorContract { +interface IFiltrator { public function filtrate($data); - public function addCustomFilter(string $filterName, callable $callback); + public function hasFilter(string $filterType): bool; - public function hasCustomFilter(string $filterName); + public function addFilterRule(string $filterName, callable $callback): self; - public function customFiltrateItem(string $filterType, array $filterParams, $data); + public function addFilter(string $filterType, array $filterParams = []): void; public function filtrateItem(string $filterType, array $filterParams, $data); - public function addFilter(string $filterType, array $filterParams): void; - - public function hasFilter(string $filterType): bool; - public function clearFilters(): void; } \ No newline at end of file diff --git a/ggrachdev.debugbar/classes/general/Writer/Contract/WritableContract.php b/ggrachdev.debugbar/classes/general/Writer/Contract/IWritable.php similarity index 94% rename from ggrachdev.debugbar/classes/general/Writer/Contract/WritableContract.php rename to ggrachdev.debugbar/classes/general/Writer/Contract/IWritable.php index 8e85283..a15058c 100644 --- a/ggrachdev.debugbar/classes/general/Writer/Contract/WritableContract.php +++ b/ggrachdev.debugbar/classes/general/Writer/Contract/IWritable.php @@ -7,7 +7,7 @@ * * @author ggrachdev */ -interface WritableContract { +interface IWritable { /** * Запись данных в ресурс diff --git a/ggrachdev.debugbar/classes/general/Writer/FileWriter.php b/ggrachdev.debugbar/classes/general/Writer/FileWriter.php index d56164f..b13b441 100644 --- a/ggrachdev.debugbar/classes/general/Writer/FileWriter.php +++ b/ggrachdev.debugbar/classes/general/Writer/FileWriter.php @@ -2,14 +2,14 @@ namespace GGrach\Writer; -use GGrach\Writer\Contract\WritableContract; +use GGrach\Writer\Contract\IWritable; /** * Запись данных в файл * * @author ggrachdev */ -class FileWriter implements WritableContract { +class FileWriter implements IWritable { /** * Запись данных в ресурс diff --git a/ggrachdev.debugbar/filters.php b/ggrachdev.debugbar/filters.php new file mode 100644 index 0000000..cb7dd37 --- /dev/null +++ b/ggrachdev.debugbar/filters.php @@ -0,0 +1,60 @@ +addFilter('values', function ($data, $filterParams) { + if (\is_array($data)) { + return \array_values($data); + } else { + return $data; + } +}); + +DD()->addFilter('limit', function ($data, $filterParams) { + if (\is_array($data) && !empty($data)) { + if (empty($filterParams[0]) || !\is_numeric($filterParams[0]) || $filterParams[0] < 1) { + $count = 10; + } else { + $count = $filterParams[0]; + } + $data = array_slice($data, 0, $count, true); + } + + return $data; +}); + +DD()->addFilter('first', function ($data, $filterParams) { + if (\is_array($data) && !empty($data)) { + $data = array_shift($data); + } + + return $data; +}); + +DD()->addFilter('keys', function ($data, $filterParams) { + + if ( + !empty($data) && + is_array($data) && + !empty($filterParams[0]) && + \is_array($filterParams[0]) + ) { + $newData = []; + + foreach ($data as $k => $v) { + if (\in_array($k, $filterParams[0])) { + $newData[$k] = $v; + } + } + + $data = $newData; + } + + return $data; +}); + +DD()->addFilter('last', function ($data, $filterParams) { + if (\is_array($data) && !empty($data)) { + $data = array_pop($data); + } + + return $data; +}); diff --git a/ggrachdev.debugbar/include.php b/ggrachdev.debugbar/include.php index f9275fc..6299e8a 100644 --- a/ggrachdev.debugbar/include.php +++ b/ggrachdev.debugbar/include.php @@ -11,7 +11,7 @@ // Папка где хранятся js $ggrachDirJs = "/bitrix/js/ggrachdev.debugbar"; -// Папка где хранятся css +// Папка где хранятся css $ggrachDirCss = "/bitrix/css/ggrachdev.debugbar"; Bitrix\Main\Loader::registerAutoLoadClasses('ggrachdev.debugbar', [ @@ -21,7 +21,7 @@ "\\GGrach\\BitrixDebugger\\Debugger\\LogFileDebugger" => "classes/general/BitrixDebugger/Debugger/LogFileDebugger.php", "\\GGrach\\BitrixDebugger\\Debugger\\ConfigurationDebugger" => "classes/general/BitrixDebugger/Debugger/ConfigurationDebugger.php", "\\GGrach\\BitrixDebugger\\Debugger\\FilterDebugger" => "classes/general/BitrixDebugger/Debugger/FilterDebugger.php", - "\\GGrach\\BitrixDebugger\\Contract\\ShowModableContract" => "classes/general/BitrixDebugger/Contract/ShowModableContract.php", + "\\GGrach\\BitrixDebugger\\Contract\\IShowModable" => "classes/general/BitrixDebugger/Contract/IShowModable.php", "\\GGrach\\BitrixDebugger\\Configurator\\DebuggerConfigurator" => "classes/general/BitrixDebugger/Configurator/DebuggerConfigurator.php", "\\GGrach\\BitrixDebugger\\Configurator\\DebugBarConfigurator" => "classes/general/BitrixDebugger/Configurator/DebugBarConfigurator.php", "\\GGrach\\BitrixDebugger\\Cache\\RuntimeCache" => "classes/general/BitrixDebugger/Cache/RuntimeCache.php", @@ -30,10 +30,10 @@ "\\GGrach\\BitrixDebugger\\Events\\OnEndBufferContent" => "classes/general/BitrixDebugger/Events/OnEndBufferContent.php", // Writer "\\GGrach\\Writer\\FileWriter" => "classes/general/Writer/FileWriter.php", - "\\GGrach\\Writer\\Contract\\WritableContract" => "classes/general/Writer/Contract/WritableContract.php", + "\\GGrach\\Writer\\Contract\\IWritable" => "classes/general/Writer/Contract/IWritable.php", // Filtrator "\\GGrach\\Filtrator\\Filtrator" => "classes/general/Filtrator/Filtrator.php", - "\\GGrach\\Filtrator\\FiltratorContract" => "classes/general/Filtrator/FiltratorContract.php" + "\\GGrach\\Filtrator\\IFiltrator" => "classes/general/Filtrator/IFiltrator.php" ]); $ggrachDebuggerConfigurator = new \GGrach\BitrixDebugger\Configurator\DebuggerConfigurator(); $ggrachDebugBarConfigurator = new \GGrach\BitrixDebugger\Configurator\DebugBarConfigurator(); @@ -82,6 +82,7 @@ function DD(...$data) { Asset::getInstance()->addCss($ggrachDirCss . '/general.css'); Asset::getInstance()->addCss($ggrachDirCss . '/' . $ggrachDebugBarConfigurator->getColorTheme() . '/theme.css'); + include 'filters.php'; include 'functions.php'; include 'events.php'; } \ No newline at end of file diff --git a/ggrachdev.debugbar/install/index.php b/ggrachdev.debugbar/install/index.php index 21f5a6a..9e25a43 100644 --- a/ggrachdev.debugbar/install/index.php +++ b/ggrachdev.debugbar/install/index.php @@ -85,6 +85,8 @@ public function installAssets() { $dirJsFrom = $_SERVER["DOCUMENT_ROOT"] . "/local/modules/" . $this->MODULE_ID . "/install/js"; } + $dirJsTo = $_SERVER["DOCUMENT_ROOT"] . "/bitrix/js/" . $this->MODULE_ID; + if ($dirJsFrom && !\is_dir($dirJsTo)) { \mkdir($dirJsTo); } @@ -92,7 +94,7 @@ public function installAssets() { \CopyDirFiles($dirJsFrom, $dirJsTo, true, true); // copy css - $dirCssTo = null; + $dirCssFrom = null; if(\is_file($_SERVER["DOCUMENT_ROOT"] . "/bitrix/modules/{$this->MODULE_ID}/install/version.php")) { @@ -103,6 +105,8 @@ public function installAssets() { $dirCssFrom = $_SERVER["DOCUMENT_ROOT"] . "/local/modules/" . $this->MODULE_ID . "/install/css"; } + $dirCssTo = $_SERVER["DOCUMENT_ROOT"] . "/bitrix/css/" . $this->MODULE_ID; + if ($dirCssTo && !\is_dir($dirCssTo)) { \mkdir($dirCssTo); } diff --git a/ggrachdev.debugbar/install/version.php b/ggrachdev.debugbar/install/version.php index 76c59ee..7d3dba4 100644 --- a/ggrachdev.debugbar/install/version.php +++ b/ggrachdev.debugbar/install/version.php @@ -1,6 +1,6 @@ "0.0.7", - "VERSION_DATE" => "2021-05-24 10:00:00" + "VERSION" => "0.0.8", + "VERSION_DATE" => "2021-05-26 10:00:00" ); ?> \ No newline at end of file