Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
inmemory.php
1<?php
2
4
7
8class InMemory extends CounterState
9{
10 private array $state = [];
11
12 public function __construct(int $userId, Counter\Loader $loader)
13 {
14 parent::__construct($userId, $loader);
15 }
16
17 public function rewind(): void
18 {
19 reset($this->state);
20 }
21
22 public function current()
23 {
24 return current($this->state);
25 }
26
27 public function key()
28 {
29 return key($this->state);
30 }
31
32 public function next(): void
33 {
34 next($this->state);
35 }
36
37 public function valid(): bool
38 {
39 $key = key($this->state);
40 return ($key !== null && $key !== false);
41 }
42
43 public function getSize(): int
44 {
45 return count($this->state);
46 }
47
48 public function updateState(array $rawCounters, array $types = [], array $logIds = []): void
49 {
50 if (empty($logIds) && empty($types))
51 {
52 $this->state = [];
53 }
54 foreach ($this as $k => $row)
55 {
56 if (
57 !empty($logIds)
58 && !in_array($row['SONET_LOG_ID'], $logIds)
59 )
60 {
61 continue;
62 }
63
64 if (
65 !empty($types)
66 && !in_array($row['TYPE'], $types)
67 )
68 {
69 continue;
70 }
71 unset($this->state[$k]);
72 }
73 foreach ($rawCounters as $k => $row)
74 {
75 if (is_null($row))
76 {
77 unset($rawCounters[$k]);
78 }
79 }
80
81 $this->state = array_merge($this->state, $rawCounters);
82
83 $this->updateRawCounters();
84 }
85
86 protected function loadCounters(): void
87 {
88 $this->updateState(
89 $this->getLoader()->getRawCounters()
90 );
91 }
92}
getRawCounters(string $meta=CounterDictionary::META_PROP_ALL)
updateState(array $rawCounters, array $types=[], array $logIds=[])
Definition inmemory.php:48