1C-Bitrix 25.700.0
Загрузка...
Поиск...
Не найдено
StateService.php
См. документацию.
1<?php
2
4
9
10final 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}
Определения json.php:9
createState(array $payload, bool $appendTimestamp=true, Context $context=null)
Определения StateService.php:35
getPayload(string $state)
Определения StateService.php:56
</td ></tr ></table ></td ></tr >< tr >< td class="bx-popup-label bx-width30"><?=GetMessage("PAGE_NEW_TAGS")?> array( $site)
Определения file_new.php:804
$context
Определения csv_new_setup.php:223
Определения culture.php:9