Issues (4)

src/BxKint.php (4 issues)

Labels
Severity
1
<?php
2
namespace App;
3
4
use Bitrix\Main\Application;
0 ignored issues
show
The type Bitrix\Main\Application was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
5
use Bitrix\Main\EventManager;
0 ignored issues
show
The type Bitrix\Main\EventManager was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
6
7
class BxKint {
8
9
    const GET_PARAM = 'app_bx_kint';
10
    const SESSION_KEY = 'APP_BX_KINT';
11
12
    public static function init() {
13
14
        if(class_exists('Kint\Kint')) {
15
            EventManager::getInstance()->addEventHandler('main', 'OnBeforeProlog', ['\App\BxKint', 'addButton']);
16
            EventManager::getInstance()->addEventHandler('main', 'OnEpilog', ['\App\BxKint', 'showInfo']);
17
        }
18
    }
19
20
    public static function showInfo() {
21
22
        global $BX_KINT_INFO;
23
        \Kint::$display_called_from = false;
24
        if(self::checkAccess() && $_SESSION[self::SESSION_KEY]) {
25
            d($BX_KINT_INFO);
26
        }
27
    }
28
29
    public static function info($var) {
30
31
        global $BX_KINT_INFO;
32
33
        if(is_array($var)) {
34
            if(!is_array($BX_KINT_INFO)) {
35
                $BX_KINT_INFO = [];
36
            }
37
            $BX_KINT_INFO = array_merge($BX_KINT_INFO, $var);
38
        } else {
39
            $BX_KINT_INFO[] = $var;
40
        }
41
    }
42
43
    public static function addButton() {
44
45
        /** @global Application */
46
        global $APPLICATION;
47
48
        if(self::checkAccess()) {
49
50
            self::checkIcons();
51
52
            $query = $_GET[self::GET_PARAM];
53
            if($query == 'Y') {
54
                $_SESSION[self::SESSION_KEY] = true;
55
            } else if($query == 'N') {
56
                $_SESSION[self::SESSION_KEY] = false;
57
            }
58
            $enabled = (bool) $_SESSION[self::SESSION_KEY];
59
60
            $queryList = (array) $_GET;
61
            $queryList[self::GET_PARAM] = ($enabled ? 'N' : 'Y');
62
63
            $button = [
64
                'HREF'      => '?' . http_build_query($queryList),
65
                'SRC'       => '/bitrix/themes/.default/icons/bxkint/debug_' . ($enabled ? 'enable' : 'disable') . '.png',
66
                'TYPE'      => 'SMALL',
67
                'HINT'      => ['TEXT' => 'BxKint debug switch'],
68
                'MAIN_SORT' => 10000,
69
                'SORT'      => 100,
70
            ];
71
72
            $APPLICATION->AddPanelButton($button);
73
        }
74
    }
75
76
    protected static function checkAccess() {
77
78
        /** @global \CUser */
79
        global $USER;
80
81
        if(is_object($USER)) {
82
            if($USER->IsAdmin())  return true;
83
            if(class_exists('CTopPanel')) {
84
                return \CTopPanel::shouldShowPanel();
0 ignored issues
show
The type CTopPanel was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
85
            }
86
        }
87
        return false;
88
    }
89
90
    protected static function checkIcons() {
91
92
        if(!file_exists($_SERVER['DOCUMENT_ROOT'] . '/bitrix/themes/.default/icons/bxkint/debug_enable.png')) {
93
            mkdir($_SERVER['DOCUMENT_ROOT'] . '/bitrix/themes/.default/icons/bxkint', BX_DIR_PERMISSIONS);
0 ignored issues
show
The constant App\BX_DIR_PERMISSIONS was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
94
95
            copy(__DIR__ . '/../resources/icons/debug_enable.png',
96
                $_SERVER['DOCUMENT_ROOT'] . '/bitrix/themes/.default/icons/bxkint/debug_enable.png');
97
            copy(__DIR__ . '/../resources/icons/debug_disable.png',
98
                $_SERVER['DOCUMENT_ROOT'] . '/bitrix/themes/.default/icons/bxkint/debug_disable.png');
99
        }
100
    }
101
}
102