1C-Bitrix
25.700.0
Загрузка...
Поиск...
Не найдено
abstractsessionhandler.php
См. документацию.
1
<?php
2
3
namespace
Bitrix\Main\Session\Handlers
;
4
5
use
Bitrix\Main\Application
;
6
use
Bitrix\Main\HttpResponse
;
7
use
Bitrix\Main\Security\Random
;
8
9
abstract
class
AbstractSessionHandler
implements
\SessionHandlerInterface, \SessionUpdateTimestampHandlerInterface, \SessionIdInterface
10
{
11
public
const
LOCK_ERROR_MESSAGE
=
'Unable to get session lock within 60 seconds.'
;
12
14
protected
$readOnly
=
false
;
16
protected
$sessionId
;
18
private
$prefetchId;
20
private
$prefetchData;
22
private
$lastCreatedId;
24
private
$listValidatedIds = [];
26
private
$releaseLockAfterClose =
true
;
27
28
#[\ReturnTypeWillChange]
29
public
function
read
(
$sessionId
)
30
{
31
if
(!$this->
validateSessionId
(
$sessionId
))
32
{
33
return
''
;
34
}
35
36
$this->sessionId =
$sessionId
;
37
if
($this->prefetchId !==
null
)
38
{
39
$prefetchId = $this->prefetchId;
40
$prefetchData = $this->prefetchData;
41
42
$this->prefetchId =
null
;
43
$this->prefetchData =
null
;
44
45
if
($prefetchId === $this->sessionId)
46
{
47
return
$prefetchData;
48
}
49
}
50
51
if
(!$this->readOnly && !$this->
lock
($this->sessionId))
52
{
53
$this->
triggerLockFatalError
();
54
}
55
56
return
$this->
processRead
(
$sessionId
);
57
}
58
59
abstract
protected
function
processRead
(
$sessionId
): string;
60
61
protected
function
triggerLockFatalError
(
string
$additionalText =
''
): void
62
{
63
$text
= self::LOCK_ERROR_MESSAGE;
64
if
($additionalText)
65
{
66
$text
.= $additionalText;
67
}
68
69
$httpResponse =
new
HttpResponse
();
70
$httpResponse->setStatus(
'500 Internal Server Error'
);
71
trigger_error(
$text
, E_USER_ERROR);
72
Application::getInstance
()->end(0, $httpResponse);
73
}
74
75
public
function
write
(
$sessionId
, $sessionData): bool
76
{
77
if
(!$this->
validateSessionId
(
$sessionId
))
78
{
79
return
false
;
80
}
81
82
if
($this->readOnly)
83
{
84
return
true
;
85
}
86
87
return
$this->
processWrite
(
$sessionId
, $sessionData);
88
}
89
90
abstract
protected
function
processWrite
(
$sessionId
, $sessionData): bool;
91
92
abstract
protected
function
lock
(
$sessionId
): bool;
93
94
abstract
protected
function
unlock
(
$sessionId
): bool;
95
96
private
function
releaseLocksAfterValidate(): void
97
{
98
unset($this->listValidatedIds[$this->sessionId]);
99
foreach
($this->listValidatedIds as $mustBeUnlockedId => $true)
100
{
101
$this->
unlock
($mustBeUnlockedId);
102
unset($this->listValidatedIds[$this->sessionId]);
103
}
104
}
105
106
public
function
close
(): bool
107
{
108
if
(!$this->readOnly && $this->
validateSessionId
($this->sessionId))
109
{
110
if
(
isSessionExpired
())
111
{
112
$this->
destroy
($this->sessionId);
113
}
114
115
if
($this->releaseLockAfterClose)
116
{
117
$this->
unlock
($this->sessionId);
118
}
119
120
$this->releaseLocksAfterValidate();
121
}
122
123
$this->sessionId =
null
;
124
$this->lastCreatedId =
null
;
125
126
return
true
;
127
}
128
129
public
function
destroy
(
$sessionId
): bool
130
{
131
if
($this->readOnly)
132
{
133
return
true
;
134
}
135
136
if
(!$this->
validateSessionId
(
$sessionId
))
137
{
138
return
false
;
139
}
140
141
$result
= $this->
processDestroy
(
$sessionId
);
142
$this->lastCreatedId =
null
;
143
144
return
$result
;
145
}
146
147
abstract
protected
function
processDestroy
(
$sessionId
): bool;
148
149
public
function
validateId
(
$sessionId
): bool
150
{
151
$this->listValidatedIds[
$sessionId
] =
true
;
152
153
$this->prefetchData = $this->
read
(
$sessionId
);
154
$this->prefetchId =
$sessionId
;
155
156
return
$this->prefetchData !==
''
;
157
}
158
159
public
function
create_sid
(): string
160
{
161
$this->lastCreatedId = Random::getString(32,
true
);
162
163
return
$this->lastCreatedId;
164
}
165
166
protected
function
validateSessionId
(
$sessionId
): bool
167
{
168
return
169
$sessionId
&&
170
is_string(
$sessionId
) &&
171
preg_match(
'/^[\da-z\-,]{6,}$/iD'
,
$sessionId
)
172
;
173
}
174
175
public
function
turnOffReleaseLockAfterCloseSession
(): void
176
{
177
$this->releaseLockAfterClose =
false
;
178
}
179
180
public
function
turnOnReleaseLockAfterCloseSession
(): void
181
{
182
$this->releaseLockAfterClose =
true
;
183
}
184
}
Bitrix\Main\Application
Определения
application.php:30
Bitrix\Main\Application\getInstance
static getInstance()
Определения
application.php:98
Bitrix\Main\HttpResponse
Определения
httpresponse.php:8
Bitrix\Main\Security\Random
Определения
random.php:6
Bitrix\Main\Session\Handlers\AbstractSessionHandler
Определения
abstractsessionhandler.php:10
Bitrix\Main\Session\Handlers\AbstractSessionHandler\create_sid
create_sid()
Определения
abstractsessionhandler.php:159
Bitrix\Main\Session\Handlers\AbstractSessionHandler\$readOnly
$readOnly
Определения
abstractsessionhandler.php:14
Bitrix\Main\Session\Handlers\AbstractSessionHandler\processWrite
processWrite($sessionId, $sessionData)
Bitrix\Main\Session\Handlers\AbstractSessionHandler\read
read($sessionId)
Определения
abstractsessionhandler.php:29
Bitrix\Main\Session\Handlers\AbstractSessionHandler\triggerLockFatalError
triggerLockFatalError(string $additionalText='')
Определения
abstractsessionhandler.php:61
Bitrix\Main\Session\Handlers\AbstractSessionHandler\turnOnReleaseLockAfterCloseSession
turnOnReleaseLockAfterCloseSession()
Определения
abstractsessionhandler.php:180
Bitrix\Main\Session\Handlers\AbstractSessionHandler\$sessionId
$sessionId
Определения
abstractsessionhandler.php:16
Bitrix\Main\Session\Handlers\AbstractSessionHandler\destroy
destroy($sessionId)
Определения
abstractsessionhandler.php:129
Bitrix\Main\Session\Handlers\AbstractSessionHandler\turnOffReleaseLockAfterCloseSession
turnOffReleaseLockAfterCloseSession()
Определения
abstractsessionhandler.php:175
Bitrix\Main\Session\Handlers\AbstractSessionHandler\lock
lock($sessionId)
Bitrix\Main\Session\Handlers\AbstractSessionHandler\close
close()
Определения
abstractsessionhandler.php:106
Bitrix\Main\Session\Handlers\AbstractSessionHandler\processRead
processRead($sessionId)
Bitrix\Main\Session\Handlers\AbstractSessionHandler\processDestroy
processDestroy($sessionId)
Bitrix\Main\Session\Handlers\AbstractSessionHandler\write
write($sessionId, $sessionData)
Определения
abstractsessionhandler.php:75
Bitrix\Main\Session\Handlers\AbstractSessionHandler\unlock
unlock($sessionId)
Bitrix\Main\Session\Handlers\AbstractSessionHandler\validateId
validateId($sessionId)
Определения
abstractsessionhandler.php:149
Bitrix\Main\Session\Handlers\AbstractSessionHandler\validateSessionId
validateSessionId($sessionId)
Определения
abstractsessionhandler.php:166
Bitrix\Main\Session\Handlers\AbstractSessionHandler\LOCK_ERROR_MESSAGE
const LOCK_ERROR_MESSAGE
Определения
abstractsessionhandler.php:11
$result
$result
Определения
get_property_values.php:14
isSessionExpired
isSessionExpired()
Определения
tools.php:5138
Bitrix\Main\Session\Handlers
Определения
abstractsessionhandler.php:3
$text
$text
Определения
template_pdf.php:79
bitrix
modules
main
lib
session
handlers
abstractsessionhandler.php
Создано системой
1.14.0