Bitrix-D7
23.9
Загрузка...
Поиск...
Не найдено
kernelsession.php
1
<?php
2
3
namespace
Bitrix\Main\Session
;
4
5
use
Bitrix\Main\NotSupportedException
;
6
use
Bitrix\Main\Security\Random
;
7
use
Bitrix\Main\Session\Handlers\CookieSessionHandler
;
8
9
class
KernelSession
implements
SessionInterface
, \ArrayAccess
10
{
11
use
ArrayAccessWithReferences
;
12
13
private
const
COOKIE_NAME =
'kernel'
;
14
16
protected
$started
;
18
protected
$sessionHandler
;
20
private
$lifetime = 0;
22
private
$id;
24
private
$hash;
25
26
public
function
__construct
(
int
$lifetime = 0)
27
{
28
$this->lifetime = $lifetime;
29
}
30
31
public
function
isActive
(): bool
32
{
33
return
$this->
isStarted
();
34
}
35
36
public
function
isAccessible
(): bool
37
{
38
return
true
;
39
}
40
41
public
function
getId
(): string
42
{
43
return
$this->id;
44
}
45
46
public
function
setId
($id)
47
{
48
throw
new
NotSupportedException
();
49
}
50
51
public
function
getName
(): string
52
{
53
throw
new
NotSupportedException
();
54
}
55
56
public
function
setName
($name)
57
{
58
throw
new
NotSupportedException
();
59
}
60
64
public
function
getSessionHandler
(): \SessionHandlerInterface
65
{
66
return
$this->sessionHandler
;
67
}
68
69
final
protected
function
hashData
(
string
$data): string
70
{
71
return
hash(
'sha512'
, $data);
72
}
73
74
public
function
start
(): bool
75
{
76
if
($this->
isStarted
())
77
{
78
return
true
;
79
}
80
81
$this->started =
true
;
82
$this->sessionHandler =
new
CookieSessionHandler
($this->lifetime);
83
$data = $this->
getSessionHandler
()->read(self::COOKIE_NAME);
84
$this->hash = $this->
hashData
($data);
85
$this->sessionData = unserialize($data, [
'allowed_classes'
=>
false
]) ?: [];
86
if
(!isset($this->sessionData[
'_id'
]))
87
{
88
$this->sessionData[
'_id'
] = Random::getString(32,
true
);
89
}
90
$this->
id
= $this->sessionData[
'_id'
];
91
92
return
true
;
93
}
94
95
public
function
regenerateId
(): bool
96
{
97
return
true
;
98
}
99
100
public
function
destroy
()
101
{
102
if
($this->
isActive
())
103
{
104
$this->
clear
();
105
}
106
}
107
108
public
function
save
()
109
{
110
$this->
refineReferencesBeforeSave
();
111
$data = serialize($this->sessionData);
112
113
if
($this->
hashData
($data) !== $this->hash)
114
{
115
$this->
getSessionHandler
()->write(self::COOKIE_NAME, $data);
116
}
117
$this->started =
false
;
118
}
119
120
public
function
clear
()
121
{
122
$this->sessionData = [];
123
$this->nullPointers = [];
124
}
125
126
public
function
isStarted
()
127
{
128
return
(
bool
)
$this->started
;
129
}
130
}
Bitrix\Main\NotSupportedException
Definition
exception.php:159
Bitrix\Main\Security\Random
Definition
random.php:6
Bitrix\Main\Session\Handlers\CookieSessionHandler
Definition
cookiesessionhandler.php:14
Bitrix\Main\Session\KernelSession
Definition
kernelsession.php:10
Bitrix\Main\Session\KernelSession\$started
$started
Definition
kernelsession.php:16
Bitrix\Main\Session\KernelSession\getId
getId()
Definition
kernelsession.php:41
Bitrix\Main\Session\KernelSession\isStarted
isStarted()
Definition
kernelsession.php:126
Bitrix\Main\Session\KernelSession\setName
setName($name)
Definition
kernelsession.php:56
Bitrix\Main\Session\KernelSession\getName
getName()
Definition
kernelsession.php:51
Bitrix\Main\Session\KernelSession\__construct
__construct(int $lifetime=0)
Definition
kernelsession.php:26
Bitrix\Main\Session\KernelSession\regenerateId
regenerateId()
Definition
kernelsession.php:95
Bitrix\Main\Session\KernelSession\getSessionHandler
getSessionHandler()
Definition
kernelsession.php:64
Bitrix\Main\Session\KernelSession\setId
setId($id)
Definition
kernelsession.php:46
Bitrix\Main\Session\KernelSession\$sessionHandler
$sessionHandler
Definition
kernelsession.php:18
Bitrix\Main\Session\KernelSession\destroy
destroy()
Definition
kernelsession.php:100
Bitrix\Main\Session\KernelSession\isActive
isActive()
Definition
kernelsession.php:31
Bitrix\Main\Session\KernelSession\clear
clear()
Definition
kernelsession.php:120
Bitrix\Main\Session\KernelSession\isAccessible
isAccessible()
Definition
kernelsession.php:36
Bitrix\Main\Session\KernelSession\hashData
hashData(string $data)
Definition
kernelsession.php:69
Bitrix\Main\Session\KernelSession\start
start()
Definition
kernelsession.php:74
Bitrix\Main\Session\KernelSession\save
save()
Definition
kernelsession.php:108
Bitrix\Main\Session\SessionInterface
Definition
sessioninterface.php:6
Bitrix\Main\Session
Definition
arrayaccesswithreferences.php:3
Bitrix\Main\Session\refineReferencesBeforeSave
refineReferencesBeforeSave()
Definition
arrayaccesswithreferences.php:95
Bitrix\Main\Session\ArrayAccessWithReferences
trait ArrayAccessWithReferences
Definition
arrayaccesswithreferences.php:8
modules
main
lib
session
kernelsession.php
Создано системой
1.10.0