Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
sessionlocalstorage.php
1<?php
3
4final class SessionLocalStorage implements \ArrayAccess, \Countable, \IteratorAggregate
5{
6 private array $data = [];
7 private string $uniqueName;
8 private string $name;
9
10 public function __construct(string $uniqueName, string $name)
11 {
12 $this->uniqueName = $uniqueName;
13 $this->name = $name;
14 }
15
19 public function getUniqueName(): string
20 {
21 return $this->uniqueName;
22 }
23
27 public function getName(): string
28 {
29 return $this->name;
30 }
31
36 public function setUniqueName(string $uniqueName): self
37 {
38 $this->uniqueName = $uniqueName;
39
40 return $this;
41 }
42
46 public function getData(): array
47 {
48 return $this->data;
49 }
50
55 public function setData(array $data)
56 {
57 $this->data = $data;
58
59 return $this;
60 }
61
62 public function &get($key)
63 {
64 return $this->data[$key];
65 }
66
67 public function set($key, $value): self
68 {
69 $this->data[$key] = $value;
70
71 return $this;
72 }
73
74 public function clear(): void
75 {
76 $this->data = [];
77 }
78
79 public function offsetExists($offset): bool
80 {
81 return isset($this->data[$offset]);
82 }
83
84 #[\ReturnTypeWillChange]
85 public function &offsetGet($offset)
86 {
87 return $this->get($offset);
88 }
89
90 public function offsetSet($offset, $value): void
91 {
92 if ($offset === null)
93 {
94 $this->data[] = $value;
95 }
96 else
97 {
98 $this->data[$offset] = $value;
99 }
100 }
101
102 public function offsetUnset($offset): void
103 {
104 unset($this->data[$offset]);
105 }
106
107 public function count(): int
108 {
109 return count($this->data);
110 }
111
112 public function getIterator(): \ArrayIterator
113 {
114 return new \ArrayIterator($this->getData());
115 }
116}