1C-Bitrix
25.700.0
Загрузка...
Поиск...
Не найдено
StateService.php
См. документацию.
1
<?php
2
3
namespace
Bitrix\Socialservices\OAuth
;
4
5
use
Bitrix\Main\Application
;
6
use
Bitrix\Main\Context
;
7
use
Bitrix\Main\Data\LocalStorage\SessionLocalStorage
;
8
use
Bitrix\Main\Web\Json
;
9
10
final
class
StateService
11
{
12
private
const
STORAGE_PREFIX =
'StateService'
;
13
private
static
self
$instance;
14
private
SessionLocalStorage
$storage;
15
16
public
function
__construct
()
17
{
18
$this->storage = Application::getInstance()->getLocalSession(self::STORAGE_PREFIX);
19
}
20
21
private
function
saveState(
string
$state,
array
$payload): void
22
{
23
$this->storage->set($state, $payload);
24
}
25
26
#region public api
27
28
public
static
function
getInstance
(): self
29
{
30
self::$instance ??=
new
self
();
31
32
return
self::$instance;
33
}
34
35
public
function
createState
(
array
$payload,
bool
$appendTimestamp =
true
,
Context
$context
=
null
): string
36
{
37
$context
??= Context::getCurrent();
38
39
$value = Json::encode($payload);
40
if
($appendTimestamp)
41
{
42
$value .= time();
43
}
44
45
$state = join(
'.'
, [
46
$payload[
'site_id'
] ??
$context
->getSite() ??
's1'
,
47
$context
->getRequest()->isAdminSection() ? 1 : 0,
48
hash(
'sha224'
, $value),
49
]);
50
51
$this->saveState($state, $payload);
52
53
return
$state;
54
}
55
56
public
function
getPayload
(
string
$state): ?
array
57
{
58
$payload = $this->storage->get($state);
59
if
(is_array($payload))
60
{
61
return
$payload;
62
}
63
64
return
null
;
65
}
66
67
#endregion public api
68
}
Bitrix\Main\Application
Определения
application.php:30
Bitrix\Main\Data\LocalStorage\SessionLocalStorage
Определения
sessionlocalstorage.php:5
Bitrix\Main\Web\Json
Определения
json.php:9
Bitrix\Socialservices\OAuth\StateService
Определения
StateService.php:11
Bitrix\Socialservices\OAuth\StateService\__construct
__construct()
Определения
StateService.php:16
Bitrix\Socialservices\OAuth\StateService\createState
createState(array $payload, bool $appendTimestamp=true, Context $context=null)
Определения
StateService.php:35
Bitrix\Socialservices\OAuth\StateService\getInstance
static getInstance()
Определения
StateService.php:28
Bitrix\Socialservices\OAuth\StateService\getPayload
getPayload(string $state)
Определения
StateService.php:56
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
Bitrix\Main\Context
Определения
culture.php:9
Bitrix\Socialservices\OAuth
Определения
StateService.php:3
bitrix
modules
socialservices
lib
OAuth
StateService.php
Создано системой
1.14.0