Bitrix-D7
23.9
Загрузка...
Поиск...
Не найдено
StateService.php
1
<?php
2
3
namespace
Bitrix\Socialservices\OAuth
;
4
5
use
Bitrix\Main\Application
;
6
use
Bitrix\Main\Data\LocalStorage\SessionLocalStorage
;
7
use
Bitrix\Main\Web\Json
;
8
9
final
class
StateService
10
{
11
private
const
STORAGE_PREFIX =
'StateService'
;
12
private
static
self
$instance;
13
private
SessionLocalStorage
$storage;
14
15
public
function
__construct
()
16
{
17
$this->storage =
Application::getInstance
()->getLocalSession(self::STORAGE_PREFIX);
18
}
19
20
private
function
saveState(
string
$state, array $payload): void
21
{
22
$this->storage->set($state, $payload);
23
}
24
25
#region public api
26
27
public
static
function
getInstance
(): self
28
{
29
self::$instance ??=
new
self
();
30
31
return
self::$instance;
32
}
33
34
public
function
createState
(array $payload,
bool
$appendTimestamp =
true
): string
35
{
36
$value = Json::encode($payload);
37
if
($appendTimestamp)
38
{
39
$value .= time();
40
}
41
42
$state = hash(
'sha224'
, $value);
43
$this->saveState($state, $payload);
44
45
return
$state;
46
}
47
48
public
function
getPayload
(
string
$state): ?array
49
{
50
$payload = $this->storage->get($state);
51
if
(is_array($payload))
52
{
53
return
$payload;
54
}
55
56
return
null
;
57
}
58
59
#endregion public api
60
}
Bitrix\Main\Application
Definition
application.php:28
Bitrix\Main\Application\getInstance
static getInstance()
Definition
application.php:95
Bitrix\Main\Data\LocalStorage\SessionLocalStorage
Definition
sessionlocalstorage.php:5
Bitrix\Main\Web\Json
Definition
json.php:11
Bitrix\Socialservices\OAuth\StateService
Definition
StateService.php:10
Bitrix\Socialservices\OAuth\StateService\__construct
__construct()
Definition
StateService.php:15
Bitrix\Socialservices\OAuth\StateService\createState
createState(array $payload, bool $appendTimestamp=true)
Definition
StateService.php:34
Bitrix\Socialservices\OAuth\StateService\getInstance
static getInstance()
Definition
StateService.php:27
Bitrix\Socialservices\OAuth\StateService\getPayload
getPayload(string $state)
Definition
StateService.php:48
Bitrix\Socialservices\OAuth
Definition
StateService.php:3
modules
socialservices
lib
OAuth
StateService.php
Создано системой
1.10.0