Skip to content
This repository was archived by the owner on Sep 6, 2023. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file modified ggrachdev.debugbar/assets/images/git/example.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,37 @@ class FilterDebugger extends ConfigurationDebugger {
*/
protected $isFreezedFilter = false;

/**
* Вызов добавленного пользователем фильтра
*
* @param type $name
* @param type $arguments
* @return $this
* @throws \BadMethodCallException
*/
public function __call($name, $arguments) {

if($this->getFiltrator()->hasCustomFilter($name))
{
$this->getFiltrator()->addFilter($name, $arguments);
}
else
{
throw new \BadMethodCallException('Not found '.$name.' method');
}

return $this;
}

public function getFiltrator(): FiltratorContract {
return $this->filtrator;
}

public function addFilter(string $nameMethod, callable $callback): self {
$this->getFiltrator()->addCustomFilter($nameMethod, $callback);
return $this;
}

public function setFiltrator(FiltratorContract $filtrator): self {
$this->filtrator = $filtrator;
return $this;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,26 +2,31 @@

namespace GGrach\BitrixDebugger\Events;

use \Bitrix\Main\Application;

/**
* Description of OnEndBufferContent
*
* @author ggrachdev
*/
class OnEndBufferContent {

public function addDebugBar(&$content) {
global $USER, $APPLICATION;

$request = Application::getInstance()->getContext()->getRequest();

if (
strpos($APPLICATION->GetCurDir(), "/bitrix/") !== false ||
$APPLICATION->GetProperty("save_kernel") == "Y" ||
!\is_object($USER) ||
!$USER->IsAdmin()
!$USER->IsAdmin() ||
$request->isAjaxRequest()
) {
return;
}

$logData = \GGrach\BitrixDebugger\Representer\DebugBarRepresenter::render(DD());
$logData = \GGrach\BitrixDebugger\View\DebugBarView::render(DD());
$content = \preg_replace("~<\s*\t*/\s*\t*body\s*\t*>~", $logData . '</body>', $content);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

namespace GGrach\BitrixDebugger\Representer;
namespace GGrach\BitrixDebugger\View;

use \GGrach\BitrixDebugger\Debugger\Debugger;

Expand All @@ -9,7 +9,7 @@
*
* @author ggrachdev
*/
class DebugBarRepresenter {
class DebugBarView {

const SYSTEM_KEYS_LOG = ['POST', 'GET', 'COOKIE', 'BX', 'SERVER'];

Expand Down Expand Up @@ -105,6 +105,8 @@ public static function render(Debugger $debugger): string {

self::addViewInRightSlot('<div class="ggrach__debug-bar__right__item ggrach_background_notice" title="Количество SQL запросов">SQL: ' . sizeof($ggrachTracker->getQueries()) . '</div>');

self::addViewInRightSlot('<a target="_blank" href="/bitrix/admin/cache.php?lang=ru" class="ggrach__debug-bar__right__item ggrach_background_success" title="Управление кешем">C</a>');

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_background_black" title="Скрыть / Раскрыть дебаг-бар">'.$closeIcon.'</a>');

$view = '<section class="ggrach__overlay" style="display: none;"></section><section class="ggrach__debug-bar '.($debugBarIsClosed ? 'hide-debug-bar' : '').'">';
Expand Down
29 changes: 27 additions & 2 deletions ggrachdev.debugbar/classes/general/Filtrator/Filtrator.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,17 @@ class Filtrator implements FiltratorContract {
'limit', 'first', 'last', 'keys'
];

private $customFilters = [];

/**
* Очередь фильтров с параметрами
*
* @var array
*/
protected $sequenceFilters;

public function addFilter(string $filterType, array $filterParams = []): void {
if ($this->hasFilter($filterType)) {
if ($this->hasFilter($filterType) || $this->hasCustomFilter($filterType)) {
$this->sequenceFilters[] = [
'type' => $filterType,
'params' => $filterParams
Expand Down Expand Up @@ -73,7 +76,13 @@ public function clearFilters(): void {
public function filtrate($data) {
if (!empty($this->sequenceFilters) && !empty($data)) {
foreach ($this->sequenceFilters as $arFilter) {
$data = $this->filtrateItem($arFilter['type'], $arFilter['params'], $data);
if($this->hasCustomFilter($arFilter['type']))
{
$data = $this->customFiltrateItem($arFilter['type'], $arFilter['params'], $data);
}
else {
$data = $this->filtrateItem($arFilter['type'], $arFilter['params'], $data);
}
}
}

Expand All @@ -84,4 +93,20 @@ public function hasFilter(string $filterType): bool {
return \in_array($filterType, self::FILTERS_NAME);
}

public function addCustomFilter(string $filterName, callable $callback) {
if (!$this->hasCustomFilter($filterName)) {
$this->customFilters[$filterName] = $callback;
}

return $this;
}

public function customFiltrateItem(string $filterType, array $filterParams, $data) {
return $this->customFilters[$filterType]($data, $filterParams);
}

public function hasCustomFilter(string $filterName) {
return \array_key_exists($filterName, $this->customFilters);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,12 @@
interface FiltratorContract {
public function filtrate($data);

public function addCustomFilter(string $filterName, callable $callback);

public function hasCustomFilter(string $filterName);

public function customFiltrateItem(string $filterType, array $filterParams, $data);

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

public function addFilter(string $filterType, array $filterParams): void;
Expand Down
4 changes: 2 additions & 2 deletions ggrachdev.debugbar/include.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
"\\GGrach\\BitrixDebugger\\Configurator\\DebugBarConfigurator" => "classes/general/BitrixDebugger/Configurator/DebugBarConfigurator.php",
"\\GGrach\\BitrixDebugger\\Cache\\RuntimeCache" => "classes/general/BitrixDebugger/Cache/RuntimeCache.php",
"\\GGrach\\BitrixDebugger\\Validator\\ShowModeDebuggerValidator" => "classes/general/BitrixDebugger/Validator/ShowModeDebuggerValidator.php",
"\\GGrach\\BitrixDebugger\\Representer\\DebugBarRepresenter" => "classes/general/BitrixDebugger/Representer/DebugBarRepresenter.php",
"\\GGrach\\BitrixDebugger\\View\\DebugBarView" => "classes/general/BitrixDebugger/View/DebugBarView.php",
"\\GGrach\\BitrixDebugger\\Events\\OnEndBufferContent" => "classes/general/BitrixDebugger/Events/OnEndBufferContent.php",
// Writer
"\\GGrach\\Writer\\FileWriter" => "classes/general/Writer/FileWriter.php",
Expand Down Expand Up @@ -73,7 +73,7 @@ function DD(...$data) {

Asset::getInstance()->addJs($ggrachDirJs . "/Index.js");
Asset::getInstance()->addJs($ggrachDirJs . "/DebugBar.js");
Asset::getInstance()->addJs($ggrachDirJs . "/User.js");
Asset::getInstance()->addJs($ggrachDirJs . "/Utils/User.js");
Asset::getInstance()->addJs($ggrachDirJs . "/Handlers.js");
Asset::getInstance()->addJs($ggrachDirJs . "/Utils/Screen.js");
Asset::getInstance()->addJs($ggrachDirJs . "/Utils/DOM.js");
Expand Down
2 changes: 1 addition & 1 deletion ggrachdev.debugbar/install/css/general.css
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
position: fixed !important;
bottom: 0 !important;
height: 30px !important;
z-index: 9999 !important;
z-index: 2099999999 !important;
display: flex !important;
align-items: center !important;
}
Expand Down
32 changes: 23 additions & 9 deletions ggrachdev.debugbar/install/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -74,20 +74,36 @@ public function DoUninstall() {
public function installAssets() {

// copy js
$dirJsFrom = $_SERVER["DOCUMENT_ROOT"] . "/bitrix/modules/" . $this->MODULE_ID . "/install/js";
$dirJsTo = $_SERVER["DOCUMENT_ROOT"] . "/bitrix/js/" . $this->MODULE_ID;
$dirJsFrom = null;

if(\is_file($_SERVER["DOCUMENT_ROOT"] . "/bitrix/modules/{$this->MODULE_ID}/install/version.php"))
{
$dirJsFrom = $_SERVER["DOCUMENT_ROOT"] . "/bitrix/modules/" . $this->MODULE_ID . "/install/js";
}
else if(\is_file($_SERVER["DOCUMENT_ROOT"] . "/local/modules/{$this->MODULE_ID}/install/version.php"))
{
$dirJsFrom = $_SERVER["DOCUMENT_ROOT"] . "/local/modules/" . $this->MODULE_ID . "/install/js";
}

if (!\is_dir($dirJsTo)) {
if ($dirJsFrom && !\is_dir($dirJsTo)) {
\mkdir($dirJsTo);
}

\CopyDirFiles($dirJsFrom, $dirJsTo, true, true);

// copy css
$dirCssFrom = $_SERVER["DOCUMENT_ROOT"] . "/bitrix/modules/" . $this->MODULE_ID . "/install/css";
$dirCssTo = $_SERVER["DOCUMENT_ROOT"] . "/bitrix/css/" . $this->MODULE_ID;

if (!\is_dir($dirCssTo)) {
$dirCssTo = null;

if(\is_file($_SERVER["DOCUMENT_ROOT"] . "/bitrix/modules/{$this->MODULE_ID}/install/version.php"))
{
$dirCssFrom = $_SERVER["DOCUMENT_ROOT"] . "/bitrix/modules/" . $this->MODULE_ID . "/install/css";
}
else if(\is_file($_SERVER["DOCUMENT_ROOT"] . "/local/modules/{$this->MODULE_ID}/install/version.php"))
{
$dirCssFrom = $_SERVER["DOCUMENT_ROOT"] . "/local/modules/" . $this->MODULE_ID . "/install/css";
}

if ($dirCssTo && !\is_dir($dirCssTo)) {
\mkdir($dirCssTo);
}

Expand All @@ -97,14 +113,12 @@ public function installAssets() {
public function reinstallAssets() {

// delete js

$dirJs = "/bitrix/js/" . $this->MODULE_ID;
if (!\is_dir($dirJs)) {
\DeleteDirFilesEx($dirJs);
}

// delete css

$dirCss = "/bitrix/css/" . $this->MODULE_ID;
if (!\is_dir($dirCss)) {
\DeleteDirFilesEx($dirCss);
Expand Down
2 changes: 2 additions & 0 deletions ggrachdev.debugbar/install/js/Utils/DOM.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,13 @@ Ggrach.Utils.DOM = {
hideOverlay: function () {
Ggrach.Utils.DOM.getOverlay().style.display = 'none';
document.querySelector('body').style.overflow = null;
document.querySelector('html').style.overflow = null;
},

showOverlay: function () {
Ggrach.Utils.DOM.getOverlay().style.display = 'block';
document.querySelector('body').setAttribute('style', 'overflow: hidden !important');
document.querySelector('html').setAttribute('style', 'overflow: hidden !important');
},

getDebugBarLogsType: function (type) {
Expand Down
4 changes: 2 additions & 2 deletions ggrachdev.debugbar/install/version.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php
$arModuleVersion = array(
"VERSION" => "0.0.6",
"VERSION_DATE" => "2021-05-19 10:00:00"
"VERSION" => "0.0.7",
"VERSION_DATE" => "2021-05-24 10:00:00"
);
?>