1C-Bitrix
25.700.0
Загрузка...
Поиск...
Не найдено
cookiesessionhandler.php
См. документацию.
1
<?php
2
3
namespace
Bitrix\Main\Session\Handlers;
4
5
use Bitrix\Main\ArgumentException;
6
use Bitrix\Main\Config\Option;
7
use Bitrix\Main\Context;
8
use Bitrix\Main\Request;
9
use Bitrix\Main\Web\Cookie;
10
use Bitrix\Main\Web\CryptoCookie;
11
use Bitrix\Main\Web\Json;
12
13
class
CookieSessionHandler
implements
\SessionHandlerInterface
14
{
16
private
$request;
18
private
$response;
20
private
$lifetime;
21
22
public
function
__construct
(
int
$lifetime,
Request
$request =
null
)
23
{
24
$this->request = $request ?: Context::getCurrent()->getRequest();
25
$this->lifetime = $lifetime;
26
}
27
28
public
function
close
(): bool
29
{
30
return
true
;
31
}
32
33
private
function
setSecureAttribute(
Cookie
$cookie):
Cookie
34
{
35
$context
= Context::getCurrent();
36
if
(!
$context
)
37
{
38
return
$cookie;
39
}
40
41
$request
=
$context
->getRequest();
42
$secure = (Option::get(
'main'
,
'use_secure_password_cookies'
,
'N'
) ===
'Y'
&&
$request
->isHttps());
43
$cookie
44
->
setHttpOnly
(
true
)
45
->setSecure($secure)
46
;
47
48
return
$cookie;
49
}
50
51
public
function
destroy
($sessionId): bool
52
{
53
$cookie =
new
Cookie
($sessionId,
null
, -2628000);
54
$cookie = $this->setSecureAttribute($cookie);
55
56
$this->
getResponse
()->addCookie($cookie);
57
58
return
true
;
59
}
60
61
public
function
gc
($maxlifetime): int
62
{
63
return
0;
64
}
65
66
public
function
open
($savePath,
$name
): bool
67
{
68
return
true
;
69
}
70
71
#[\ReturnTypeWillChange]
72
public
function
read
($sessionId)
73
{
74
$value = $this->request->getCookie($sessionId) ?:
''
;
75
if
(!$value)
76
{
77
return
''
;
78
}
79
80
try
81
{
82
$decoded = Json::decode($value);
83
}
84
catch
(
ArgumentException
$exception)
85
{
86
return
''
;
87
}
88
89
if
(is_array($decoded))
90
{
91
if
(!isset($decoded[
'expires'
]))
92
{
93
return
$decoded[
'data'
];
94
}
95
if
(time() <= $decoded[
'expires'
])
96
{
97
return
$decoded[
'data'
];
98
}
99
}
100
101
return
''
;
102
}
103
104
public
function
write
($sessionId, $sessionData): bool
105
{
106
$expires = $this->lifetime ? (time() + $this->lifetime) : 0;
107
108
$value = Json::encode([
109
'data'
=> $sessionData,
110
'createdAt'
=> time(),
111
'expires'
=> $expires?:
null
,
112
]);
113
114
$cookie =
new
CryptoCookie
($sessionId, $value, $expires);
115
$cookie = $this->setSecureAttribute($cookie);
116
117
$this->
getResponse
()->addCookie($cookie);
118
119
return
true
;
120
}
121
125
public
function
getResponse
(): \
Bitrix
\
Main
\
HttpResponse
126
{
127
return
$this->response?: Context::getCurrent()->getResponse();
128
}
129
134
public
function
setResponse
($response)
135
{
136
$this->response = $response;
137
138
return
$this;
139
}
140
}
$request
if(!Loader::includeModule('catalog')) if(!AccessController::getCurrent() ->check(ActionDictionary::ACTION_PRICE_EDIT)) if(!check_bitrix_sessid()) $request
Определения
catalog_reindex.php:36
Bitrix\Main\ArgumentException
Определения
ArgumentException.php:9
Bitrix\Main\HttpResponse
Определения
httpresponse.php:8
Bitrix\Main\Request
Определения
request.php:10
Bitrix\Main\Session\Handlers\CookieSessionHandler
Определения
cookiesessionhandler.php:14
Bitrix\Main\Session\Handlers\CookieSessionHandler\__construct
__construct(int $lifetime, Request $request=null)
Определения
cookiesessionhandler.php:22
Bitrix\Main\Session\Handlers\CookieSessionHandler\open
open($savePath, $name)
Определения
cookiesessionhandler.php:66
Bitrix\Main\Session\Handlers\CookieSessionHandler\read
read($sessionId)
Определения
cookiesessionhandler.php:72
Bitrix\Main\Session\Handlers\CookieSessionHandler\gc
gc($maxlifetime)
Определения
cookiesessionhandler.php:61
Bitrix\Main\Session\Handlers\CookieSessionHandler\getResponse
getResponse()
Определения
cookiesessionhandler.php:125
Bitrix\Main\Session\Handlers\CookieSessionHandler\destroy
destroy($sessionId)
Определения
cookiesessionhandler.php:51
Bitrix\Main\Session\Handlers\CookieSessionHandler\close
close()
Определения
cookiesessionhandler.php:28
Bitrix\Main\Session\Handlers\CookieSessionHandler\write
write($sessionId, $sessionData)
Определения
cookiesessionhandler.php:104
Bitrix\Main\Session\Handlers\CookieSessionHandler\setResponse
setResponse($response)
Определения
cookiesessionhandler.php:134
Bitrix\Main\Web\Cookie
Определения
cookie.php:9
Bitrix\Main\Web\CryptoCookie
Определения
cryptocookie.php:10
Bitrix\Main\Web\Http\Cookie\setHttpOnly
setHttpOnly(bool $httpOnly)
Определения
cookie.php:64
$context
$context
Определения
csv_new_setup.php:223
$name
$name
Определения
menu_edit.php:35
Bitrix\Main
Bitrix
bitrix
modules
main
lib
session
handlers
cookiesessionhandler.php
Создано системой
1.14.0