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
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@
border-bottom: 1px solid #c3c3c3 !important;
font-size: 13px !important;
line-height: 16px !important;
margin: 0 !important;
}

.ggrach__debug_bar__log > pre > code {
Expand Down
Binary file added assets/DebugBar/images/git/example_for_git.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
16 changes: 12 additions & 4 deletions assets/DebugBar/js/initializer.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,16 @@ Ggrach.Utils.User = {

Ggrach.Utils.DOM = {

hideOverlay: function () {
Ggrach.Utils.DOM.getOverlay().style.display = 'none';
},

showOverlay: function () {
Ggrach.Utils.DOM.getOverlay().style.display = 'block';
},

getDebugBarLogsType: function (type) {
return document.querySelector('.ggrach__debug_bar__log[data-type-notice="' + type + '"]')
return document.querySelector('.ggrach__debug_bar__log[data-type-notice="' + type + '"]');
},

getDebugBarLogs: function () {
Expand All @@ -82,7 +90,7 @@ Ggrach.Handlers = {

// Нажатие клавиши esc
onKeyEsc: function (e) {
if ((e.key == 'Escape' || e.key == 'Esc' || e.keyCode == 27) && (e.target.nodeName == 'BODY')) {
if ((e.key === 'Escape' || e.key === 'Esc' || e.keyCode == 27) && (e.target.nodeName === 'BODY')) {

if (document.querySelector('[data-type-notice].active'))
{
Expand Down Expand Up @@ -116,13 +124,13 @@ Ggrach.Handlers = {
e.target.classList.remove('active');
document.querySelector('body').style.overflow = null;
$targetLogPanel.style.display = 'none';
Ggrach.Utils.DOM.getOverlay().style.display = 'none';
Ggrach.Utils.DOM.hideOverlay();
} else
{
e.target.classList.add('active');
document.querySelector('body').style.overflow = 'hidden';
$targetLogPanel.style.display = 'block';
Ggrach.Utils.DOM.getOverlay().style.display = 'block';
Ggrach.Utils.DOM.showOverlay();
}
}
};
Expand Down
37 changes: 8 additions & 29 deletions events.php
Original file line number Diff line number Diff line change
@@ -1,31 +1,10 @@
<?php

// Добавляем дебаг-бар
AddEventHandler("main", "OnEndBufferContent", "GgrachAddDebugBar");

function GgrachAddDebugBar(&$content) {

global $USER, $APPLICATION;

if (
strpos($APPLICATION->GetCurDir(), "/bitrix/") !== false) {
return;
}

if ($APPLICATION->GetProperty("save_kernel") == "Y") {
return;
}

if(!\is_object($USER))
{
return;
}

if(!$USER->IsAdmin())
{
return;
}

$logData = \GGrach\BitrixDebugger\Representer\DebugBarRepresenter::render(GD());
$content = \str_replace('</body>', $logData . '</body>', $content);
}
\Bitrix\Main\EventManager::getInstance()->addEventHandler(
"main",
"OnEndBufferContent",
[
"\\GGrach\\BitrixDebugger\\Events\\OnEndBufferContent",
"addDebugBar"
]
);
73 changes: 13 additions & 60 deletions initializer.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,74 +3,27 @@
/**
* https://github.com/ggrachdev/BitrixDebugger
* @author ggrachdev@yandex.ru
* @version 0.02
* @version 0.03 beta
*
* Пример дебага:
*
* GD()->notice('Моя переменная', 'Моя переменная 2');
* GD()->error('Моя переменная', 'Моя переменная 2');
* GD()->warning('Моя переменная', 'Моя переменная 2');
* GD()->success('Моя переменная', 'Моя переменная 2');
* DD()->notice('Моя переменная', 'Моя переменная 2');
* DD()->error('Моя переменная', 'Моя переменная 2');
* DD()->warning('Моя переменная', 'Моя переменная 2');
* DD()->success('Моя переменная', 'Моя переменная 2');
*
* Залогировать в файлы
* GD()->noticeLog('Моя переменная', 'Моя переменная 2');
* GD()->errorLog('Моя переменная', 'Моя переменная 2');
* GD()->warningLog('Моя переменная', 'Моя переменная 2');
* GD()->successLog('Моя переменная', 'Моя переменная 2');
* DD()->noticeLog('Моя переменная', 'Моя переменная 2');
* DD()->errorLog('Моя переменная', 'Моя переменная 2');
* DD()->warningLog('Моя переменная', 'Моя переменная 2');
* DD()->successLog('Моя переменная', 'Моя переменная 2');
*
* Нужно подключить этот файл в init.php
* include 'BitrixDebugger/initializer.php';
*
*/
use Bitrix\Main\Page\Asset;

if (!empty($_SERVER['DOCUMENT_ROOT'])) {

$ggrachDebuggerRootPath = str_replace($_SERVER['DOCUMENT_ROOT'], '', __DIR__);

\Bitrix\Main\Loader::registerAutoLoadClasses(null, [
"\GGrach\BitrixDebugger\Debugger\Debugger" => $ggrachDebuggerRootPath . "/src/BitrixDebugger/Debugger/Debugger.php",
"\GGrach\BitrixDebugger\Debugger\DebuggerShowModable" => $ggrachDebuggerRootPath . "/src/BitrixDebugger/Debugger/DebuggerShowModable.php",
"\GGrach\BitrixDebugger\Contract\ShowModableContract" => $ggrachDebuggerRootPath . "/src/BitrixDebugger/Contract/ShowModableContract.php",
"\GGrach\BitrixDebugger\Configurator\DebuggerConfigurator" => $ggrachDebuggerRootPath . "/src/BitrixDebugger/Configurator/DebuggerConfigurator.php",
"\GGrach\BitrixDebugger\Configurator\DebugBarConfigurator" => $ggrachDebuggerRootPath . "/src/BitrixDebugger/Configurator/DebugBarConfigurator.php",
"\GGrach\BitrixDebugger\Cache\RuntimeCache" => $ggrachDebuggerRootPath . "/src/BitrixDebugger/Cache/RuntimeCache.php",
"\GGrach\BitrixDebugger\Validator\ShowModeDebuggerValidator" => $ggrachDebuggerRootPath . "/src/BitrixDebugger/Validator/ShowModeDebuggerValidator.php",
"\GGrach\BitrixDebugger\Representer\DebugBarRepresenter" => $ggrachDebuggerRootPath . "/src/BitrixDebugger/Representer/DebugBarRepresenter.php",
"\GGrach\Writer\FileWriter" => $ggrachDebuggerRootPath . "/src/Writer/FileWriter.php",
"\GGrach\Writer\Contract\WritableContract" => $ggrachDebuggerRootPath . "/src/Writer/Contract/WritableContract.php"
]);

$ggrachDebuggerConfigurator = new \GGrach\BitrixDebugger\Configurator\DebuggerConfigurator();
$ggrachDebugBarConfigurator = new \GGrach\BitrixDebugger\Configurator\DebugBarConfigurator();

$ggrachDebuggerConfigurator->setLogPath('error', __DIR__ . '/logs/error.log');
$ggrachDebuggerConfigurator->setLogPath('warning', __DIR__ . '/logs/warning.log');
$ggrachDebuggerConfigurator->setLogPath('success', __DIR__ . '/logs/success.log');
$ggrachDebuggerConfigurator->setLogPath('notice', __DIR__ . '/logs/notice.log');

global $GD;
$GD = new \GGrach\BitrixDebugger\Debugger\Debugger($ggrachDebuggerConfigurator, $ggrachDebugBarConfigurator);

/*
* code - отображать дебаг-данные в коде
* debug_bar - отображать дебаг-данные в debug_bar
*/
$GD->setShowModes(['code', 'debug_bar']);

function GD() {
global $GD;
return $GD;
}

if (\GGrach\BitrixDebugger\Validator\ShowModeDebuggerValidator::needShowInDebugBar($GD)) {

Asset::getInstance()->addJs($ggrachDebuggerRootPath . "/assets/DebugBar/js/initializer.js");
Asset::getInstance()->addCss($ggrachDebuggerRootPath . '/assets/DebugBar/themes/general.css');
Asset::getInstance()->addCss($ggrachDebuggerRootPath . '/assets/DebugBar/themes/' . $ggrachDebugBarConfigurator->getColorTheme() . '/theme.css');

include 'functions.php';

include 'events.php';
}
if (\php_sapi_name() === 'cli') {
include 'initializers/cli.php';
} else {
include 'initializers/server.php';
}
10 changes: 10 additions & 0 deletions initializers/cli.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?
// Укажите ваш DOCUMENT_ROOT
$_SERVER['DOCUMENT_ROOT'] = '/home/c/cq01452/public_html';

if (!empty($_SERVER['DOCUMENT_ROOT'])) {

$_SERVER['DOCUMENT_ROOT'] = rtrim($_SERVER['DOCUMENT_ROOT'], '/');

include 'server.php';
}
50 changes: 50 additions & 0 deletions initializers/server.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
<?

use Bitrix\Main\Page\Asset;

$ggrachDebuggerRootPath = str_replace($_SERVER['DOCUMENT_ROOT'], '', __DIR__ . '/..');
$ggrachPathLogFolder = \realpath('.'.$ggrachDebuggerRootPath.'/logs');

\Bitrix\Main\Loader::registerAutoLoadClasses(null, [
"\GGrach\BitrixDebugger\Debugger\Debugger" => $ggrachDebuggerRootPath . "/src/BitrixDebugger/Debugger/Debugger.php",
"\GGrach\BitrixDebugger\Debugger\DebuggerShowModable" => $ggrachDebuggerRootPath . "/src/BitrixDebugger/Debugger/DebuggerShowModable.php",
"\GGrach\BitrixDebugger\Contract\ShowModableContract" => $ggrachDebuggerRootPath . "/src/BitrixDebugger/Contract/ShowModableContract.php",
"\GGrach\BitrixDebugger\Configurator\DebuggerConfigurator" => $ggrachDebuggerRootPath . "/src/BitrixDebugger/Configurator/DebuggerConfigurator.php",
"\GGrach\BitrixDebugger\Configurator\DebugBarConfigurator" => $ggrachDebuggerRootPath . "/src/BitrixDebugger/Configurator/DebugBarConfigurator.php",
"\GGrach\BitrixDebugger\Cache\RuntimeCache" => $ggrachDebuggerRootPath . "/src/BitrixDebugger/Cache/RuntimeCache.php",
"\GGrach\BitrixDebugger\Validator\ShowModeDebuggerValidator" => $ggrachDebuggerRootPath . "/src/BitrixDebugger/Validator/ShowModeDebuggerValidator.php",
"\GGrach\BitrixDebugger\Representer\DebugBarRepresenter" => $ggrachDebuggerRootPath . "/src/BitrixDebugger/Representer/DebugBarRepresenter.php",
"\GGrach\Writer\FileWriter" => $ggrachDebuggerRootPath . "/src/Writer/FileWriter.php",
"\GGrach\Writer\Contract\WritableContract" => $ggrachDebuggerRootPath . "/src/Writer/Contract/WritableContract.php",
"\GGrach\BitrixDebugger\Events\OnEndBufferContent" => $ggrachDebuggerRootPath . "/src/BitrixDebugger/Events/OnEndBufferContent.php"
]);

$ggrachDebuggerConfigurator = new \GGrach\BitrixDebugger\Configurator\DebuggerConfigurator();
$ggrachDebugBarConfigurator = new \GGrach\BitrixDebugger\Configurator\DebugBarConfigurator();

$ggrachDebuggerConfigurator->setLogPath('error', $ggrachPathLogFolder . '/error.log');
$ggrachDebuggerConfigurator->setLogPath('warning', $ggrachPathLogFolder . '/warning.log');
$ggrachDebuggerConfigurator->setLogPath('success', $ggrachPathLogFolder . '/success.log');
$ggrachDebuggerConfigurator->setLogPath('notice', $ggrachPathLogFolder . '/notice.log');

$GLOBALS["DD"] = new \GGrach\BitrixDebugger\Debugger\Debugger($ggrachDebuggerConfigurator, $ggrachDebugBarConfigurator);

/*
* code - отображать дебаг-данные в коде
* debug_bar - отображать дебаг-данные в debug_bar
*/
$GLOBALS["DD"]->setShowModes(['debug_bar']);

function DD() {
return $GLOBALS["DD"];
}

if (\GGrach\BitrixDebugger\Validator\ShowModeDebuggerValidator::needShowInDebugBar($GLOBALS["DD"])) {

Asset::getInstance()->addJs($ggrachDebuggerRootPath . "/assets/DebugBar/js/initializer.js");
Asset::getInstance()->addCss($ggrachDebuggerRootPath . '/assets/DebugBar/css/themes/general.css');
Asset::getInstance()->addCss($ggrachDebuggerRootPath . '/assets/DebugBar/css/themes/' . $ggrachDebugBarConfigurator->getColorTheme() . '/theme.css');

include __DIR__.'/../functions.php';
include __DIR__.'/../events.php';
}
9 changes: 9 additions & 0 deletions phpunit.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--Bootstrap указываем относительно папки local/php_interface/BitrixDebugger чтобы выйти в DOCUMENT_ROOT-->
<phpunit bootstrap="bitrix/modules/main/include/prolog_before.php">
<testsuites>
<testsuite name="Notice raw">
<file>../../../../NoticeRawTest.php</file>
</testsuite>
</testsuites>
</phpunit>
1 change: 0 additions & 1 deletion src/BitrixDebugger/DebugBar/.gitkeep

This file was deleted.

5 changes: 4 additions & 1 deletion src/BitrixDebugger/Debugger/Debugger.php
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,10 @@ protected function noticeRaw(string $type, $arLogItems) {
}

if (ShowModeDebuggerValidator::needShowInCode($this)) {


foreach ($arLogItems as $item) {
echo \ggrach_highlight_data($item);
}
}
}

Expand Down
28 changes: 28 additions & 0 deletions src/BitrixDebugger/Events/OnEndBufferContent.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?php

namespace GGrach\BitrixDebugger\Events;

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

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

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

$logData = \GGrach\BitrixDebugger\Representer\DebugBarRepresenter::render(DD());
$content = \str_replace(['</body>', '</ body>', '</ body >', '</body >'], $logData . '</body>', $content);
}

}
1 change: 0 additions & 1 deletion src/BitrixDebugger/Facade/.gitkeep

This file was deleted.

9 changes: 5 additions & 4 deletions src/BitrixDebugger/Representer/DebugBarRepresenter.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,18 @@ class DebugBarRepresenter {

public static function render(Debugger $debugger): string {

global $DBDebug, $APPLICATION;
global $DBDebug;

$debugIsOn = false;

$bxSettings = require $_SERVER['DOCUMENT_ROOT'] . '/bitrix/.settings.php';

// $bxSettings = require $_SERVER['DOCUMENT_ROOT'] . '/bitrix/.settings.php';
$bxSettingsDebug = \Bitrix\Main\Config\Configuration::getValue("exception_handling")['debug'];

$log = $debugger->getLog();

$view = '<section class="ggrach__overlay" style="display: none;"></section><section class="ggrach__debug_bar">';

if ($DBDebug || $bxSettings['exception_handling']['value']['debug']) {
if ($DBDebug || $bxSettingsDebug) {
$debugIsOn = true;
} else {
$debugIsOn = false;
Expand Down
3 changes: 2 additions & 1 deletion src/BitrixDebugger/Validator/ShowModeDebuggerValidator.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ public static function needShowInDebugBar(ShowModableContract $debugger) {
}

public static function needShowInCode(ShowModableContract $debugger) {
return in_array('code', $debugger->getShowModes());
global $USER;
return in_array('code', $debugger->getShowModes()) && \is_object($USER) && $USER->IsAdmin();
}

}
32 changes: 32 additions & 0 deletions tests/NoticeRawTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?php

use PHPUnit\Framework\TestCase;

class NoticeRawTest extends TestCase {

public function testNotice() {
// @todo
$stack = [];
$this->assertSame(0, count($stack));

array_push($stack, 'foo');
$this->assertSame('foo', $stack[count($stack) - 1]);
$this->assertSame(1, count($stack));

$this->assertSame('foo', array_pop($stack));
$this->assertSame(0, count($stack));
}

public function testErrors() {

}

public function testSuccess() {

}

public function testWarning() {

}

}