1C-Bitrix 25.700.0
Загрузка...
Поиск...
Не найдено
filter.php
См. документацию.
1<?php
2
3namespace Bitrix\Translate;
4
19class Filter implements \Iterator, \Countable, \Serializable, \ArrayAccess
20{
21 const STORAGE_NAME = 'TRANSLATE_FILTER';
22 const STORAGE_TAB_CNT = 'TRANSLATE_FILTER_TAB';
23
24 private array $params = [];
25
26 private array $iterateCodes = [];
27
28 private int $iteratePosition = 0;
29
30
36 public function __construct($param = null)
37 {
38 if (\is_array($param))
39 {
40 $this->params = $param;
41 }
42 elseif (\is_int($param) && (int)$param > 0)
43 {
44 $this->restore((int)$param);
45 }
46 }
47
48 //region getter/setter
49
57 public function __isset($code)
58 {
59 return isset($this->params[$code]);
60 }
61
69 public function __get($code)
70 {
71 return $this->params[$code] ?: null;
72 }
73
82 public function __set($code, $value)
83 {
84 $this->params[$code] = $value;
85 $this->iterateCodes[] = $code;
86 }
87
95 public function __unset($code)
96 {
97 if (isset($this->params[$code]))
98 {
99 unset($this->params[$code]);
100 $this->iterateCodes = \array_keys($this->params);
101 }
102 }
103
104 //endregion
105
106 //region Iterator
107
113 #[\ReturnTypeWillChange]
114 public function current()
115 {
116 $code = $this->iterateCodes[$this->iteratePosition];
117
118 return $this->params[$code] ?: null;
119 }
120
126 public function next(): void
127 {
128 ++ $this->iteratePosition;
129 }
130
136 #[\ReturnTypeWillChange]
137 public function key()
138 {
139 return $this->iterateCodes[$this->iteratePosition] ?: null;
140 }
141
147 public function valid(): bool
148 {
149 return isset($this->iterateCodes[$this->iteratePosition], $this->params[$this->iterateCodes[$this->iteratePosition]]);
150 }
151
157 public function rewind(): void
158 {
159 $this->iteratePosition = 0;
160 $this->iterateCodes = \array_keys($this->params);
161 }
162
163 //endregion
164
165 // region Serializable
166
171 public function serialize(): string
172 {
173 return \serialize($this->params);
174 }
175
180 public function unserialize($data): void
181 {
182 if (!empty($data))
183 {
184 $deserialized = \unserialize($data, ['allowed_classes' => false]);
185 if (\is_array($deserialized))
186 {
187 $this->params = $deserialized;
188 }
189 }
190 }
191
192 //endregion
193
194 // region Storage
195
201 public static function getTabId(bool $increment = true): int
202 {
203 $tabId = 0;
204 if (isset($_SESSION[self::STORAGE_TAB_CNT]))
205 {
206 $tabId = $_SESSION[self::STORAGE_TAB_CNT];
207 }
208 if ($increment)
209 {
210 $tabId ++;
211 $_SESSION[self::STORAGE_TAB_CNT] = $tabId;
212 }
213
214 return $tabId;
215 }
216
217
222 public function store(): void
223 {
224 if (!isset($_SESSION[self::STORAGE_NAME]))
225 {
226 $_SESSION[self::STORAGE_NAME] = [];
227 }
228 if (!isset($this->tabId))
229 {
230 $this->tabId = self::getTabId();
231 }
232
233 $_SESSION[self::STORAGE_NAME][$this->tabId] = $this->serialize();
234 }
235
240 public function restore(int $id): void
241 {
242 if (isset($_SESSION[self::STORAGE_NAME], $_SESSION[self::STORAGE_NAME][$id]))
243 {
244 $this->unserialize($_SESSION[self::STORAGE_NAME][$id]);
245 }
246 $this->tabId = $id;
247 }
248
249 // endregion
250
251 //region ArrayAccess
252
260 public function offsetExists($code): bool
261 {
262 return isset($this->params[$code]);
263 }
264
272 #[\ReturnTypeWillChange]
273 public function offsetGet($code)
274 {
275 if (isset($this->params[$code]))
276 {
277 return $this->params[$code];
278 }
279
280 return null;
281 }
282
291 public function offsetSet($code, $param): void
292 {
293 $this->params[$code] = $param;
294 }
295
303 public function offsetUnset($code): void
304 {
305 if (isset($this->params[$code]))
306 {
307 unset($this->params[$code]);
308 }
309 }
310
311 // endregion
312
313 //region Countable
314
320 public function count(): int
321 {
322 return \is_array($this->params) ? \count($this->params) : 0;
323 }
324
325 //endregion
326}
restore(int $id)
Определения filter.php:240
offsetGet($code)
Определения filter.php:273
const STORAGE_TAB_CNT
Определения filter.php:22
serialize()
Определения filter.php:171
offsetSet($code, $param)
Определения filter.php:291
__get($code)
Определения filter.php:69
key()
Определения filter.php:137
__unset($code)
Определения filter.php:95
const STORAGE_NAME
Определения filter.php:21
static getTabId(bool $increment=true)
Определения filter.php:201
offsetExists($code)
Определения filter.php:260
unserialize($data)
Определения filter.php:180
store()
Определения filter.php:222
__isset($code)
Определения filter.php:57
valid()
Определения filter.php:147
__set($code, $value)
Определения filter.php:82
offsetUnset($code)
Определения filter.php:303
count()
Определения filter.php:320
next()
Определения filter.php:126
rewind()
Определения filter.php:157
__construct($param=null)
Определения filter.php:36
current()
Определения filter.php:114
$data['IS_AVAILABLE']
Определения .description.php:13
</td ></tr ></table ></td ></tr >< tr >< td class="bx-popup-label bx-width30"><?=GetMessage("PAGE_NEW_TAGS")?> array( $site)
Определения file_new.php:804
if(!is_null($config))($config as $configItem)(! $configItem->isVisible()) $code
Определения options.php:195
if( $daysToExpire >=0 &&$daysToExpire< 60 elseif)( $daysToExpire< 0)
Определения prolog_main_admin.php:393