1C-Bitrix
25.700.0
Загрузка...
Поиск...
Не найдено
debugger.php
См. документацию.
1
<?php
2
3
namespace
Bitrix\Main\Session;
4
5
use Bitrix\Main\Application;
6
use Bitrix\Main\Context;
7
use Bitrix\Main\Diag\Helper;
8
use Bitrix\Main\EventManager;
9
use Bitrix\Main\Security\Cipher;
10
use Bitrix\Main\Security\SecurityException;
11
12
final
class
Debugger
13
{
14
public
const
TO_FILE
= 0b001;
15
public
const
TO_HEADER
= 0b010;
16
public
const
TO_ALL
= self::TO_FILE | self::TO_HEADER;
17
18
protected
int
$mode
= 0;
19
private
array
$config = [];
20
21
public
function
__construct
(
int
$mode
= 0)
22
{
23
$this->
setMode
($mode);
24
25
EventManager::getInstance
()->addEventHandlerCompatible(
'main'
,
'OnPageStart'
,
function
(){
26
$this->
logConfiguration
($this->config);
27
});
28
}
29
30
public
function
setMode
(
int
$mode
): void
31
{
32
$this->mode =
$mode
;
33
}
34
35
public
function
logConfiguration
(
array
$config): void
36
{
37
$mode
= $config[
'mode'
] ??
'unknown'
;
38
$type
= $config[
'handlers'
][
'general'
][
'type'
] ??
'unknown'
;
39
40
$this->
addHeader
(
'Conf'
,
"{$mode}:{$type}"
);
41
}
42
43
public
function
detectFirstUsage
(): void
44
{
45
$firstUsage =
null
;
46
$traceItems = Helper::getBackTrace(10, DEBUG_BACKTRACE_IGNORE_ARGS, 4);
47
foreach
($traceItems as $item)
48
{
49
if
($this->isInternalSessionLine($item))
50
{
51
continue
;
52
}
53
54
$firstUsage =
"{$item['file']}:{$item['line']}"
;
55
break
;
56
}
57
58
if
($firstUsage)
59
{
60
$this->
addHeader
(
"Usage"
, $firstUsage);
61
}
62
}
63
69
private
function
isInternalSessionLine(
array
$item): bool
70
{
71
if
(empty($item[
'class'
]))
72
{
73
return
false
;
74
}
75
76
if
(strpos($item[
'file'
],
'lib'
. DIRECTORY_SEPARATOR .
'session'
. DIRECTORY_SEPARATOR))
77
{
78
return
true
;
79
}
80
if
(strpos($item[
'file'
],
'storage'
. DIRECTORY_SEPARATOR .
'nativesessionstorage'
))
81
{
82
return
true
;
83
}
84
85
return
false
;
86
}
87
88
public
function
logToFile
(
$text
): void
89
{
90
if
($this->mode & self::TO_FILE)
91
{
92
$requestUri
=
Application::getInstance
()->getContext()->getServer()->getRequestUri();
93
AddMessage2Log
(
$text
.
' '
.
$requestUri
,
'main'
, 20);
94
}
95
}
96
97
protected
function
addHeader
(
string
$category,
string
$value): void
98
{
99
$context
= Context::getCurrent();
100
if
(!(
$context
instanceof
Context
))
101
{
102
return
;
103
}
104
105
if
($this->mode & self::TO_HEADER)
106
{
107
if
($this->
shouldEncryptValue
())
108
{
109
$value = $this->
encryptValue
($value);
110
}
111
112
$response
=
$context
->getResponse();
113
$response
->addHeader(
"X-Session-{$category}"
, $value);
114
}
115
}
116
117
protected
function
getCryptoKey
(): ?string
118
{
119
return
$this->config[
'debugKey'
] ??
null
;
120
}
121
122
protected
function
shouldEncryptValue
(): bool
123
{
124
return
!empty($this->
getCryptoKey
());
125
}
126
127
protected
function
encryptValue
(
string
$value): string
128
{
129
try
130
{
131
$cipher =
new
Cipher
();
132
$encryptedValue = $cipher->encrypt($value, $this->
getCryptoKey
());
133
134
return
$this->encodeUrlSafeB64($encryptedValue);
135
}
136
catch
(
SecurityException
$securityException)
137
{
138
return
''
;
139
}
140
}
141
142
private
function
encodeUrlSafeB64(
string
$input): string
143
{
144
return
str_replace(
'='
,
''
, strtr(base64_encode($input),
'+/'
,
'-_'
));
145
}
146
147
public
function
storeConfig
(
array
$sessionConfig): void
148
{
149
$this->config = $sessionConfig;
150
}
151
}
$type
$type
Определения
options.php:106
Bitrix\Main\Application\getInstance
static getInstance()
Определения
application.php:98
Bitrix\Main\EventManager\getInstance
static getInstance()
Определения
eventmanager.php:31
Bitrix\Main\Security\Cipher
Определения
cipher.php:11
Bitrix\Main\Security\SecurityException
Определения
securityexception.php:6
Bitrix\Main\Session\Debugger
Определения
debugger.php:13
Bitrix\Main\Session\Debugger\storeConfig
storeConfig(array $sessionConfig)
Определения
debugger.php:147
Bitrix\Main\Session\Debugger\TO_FILE
const TO_FILE
Определения
debugger.php:14
Bitrix\Main\Session\Debugger\logToFile
logToFile($text)
Определения
debugger.php:88
Bitrix\Main\Session\Debugger\addHeader
addHeader(string $category, string $value)
Определения
debugger.php:97
Bitrix\Main\Session\Debugger\getCryptoKey
getCryptoKey()
Определения
debugger.php:117
Bitrix\Main\Session\Debugger\shouldEncryptValue
shouldEncryptValue()
Определения
debugger.php:122
Bitrix\Main\Session\Debugger\detectFirstUsage
detectFirstUsage()
Определения
debugger.php:43
Bitrix\Main\Session\Debugger\TO_HEADER
const TO_HEADER
Определения
debugger.php:15
Bitrix\Main\Session\Debugger\$mode
int $mode
Определения
debugger.php:18
Bitrix\Main\Session\Debugger\__construct
__construct(int $mode=0)
Определения
debugger.php:21
Bitrix\Main\Session\Debugger\setMode
setMode(int $mode)
Определения
debugger.php:30
Bitrix\Main\Session\Debugger\TO_ALL
const TO_ALL
Определения
debugger.php:16
Bitrix\Main\Session\Debugger\encryptValue
encryptValue(string $value)
Определения
debugger.php:127
Bitrix\Main\Session\Debugger\logConfiguration
logConfiguration(array $config)
Определения
debugger.php:35
array
</td ></tr ></table ></td ></tr >< tr >< td class="bx-popup-label bx-width30"><?=GetMessage("PAGE_NEW_TAGS")?> array( $site)
Определения
file_new.php:804
$context
$context
Определения
csv_new_setup.php:223
$requestUri
$requestUri
Определения
urlrewrite.php:51
AddMessage2Log
AddMessage2Log($text, $module='', $traceDepth=6, $showArgs=false)
Определения
tools.php:3941
Bitrix\Main\Context
Определения
culture.php:9
$text
$text
Определения
template_pdf.php:79
$response
$response
Определения
result.php:21
bitrix
modules
main
lib
session
debugger.php
Создано системой
1.14.0