Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
page.php
1<?php
2
4
6
7final class Page implements Arrayable, \IteratorAggregate, \ArrayAccess, \JsonSerializable
8{
10 private $id;
12 private $items = [];
13
15 private $totalCount;
16 private $calculatedTotalCount;
17
23 public function __construct($id, $items, $totalCount)
24 {
25 $data = [];
26 if (!is_array($items) && $items instanceof \Traversable)
27 {
28 foreach ($items as $item)
29 {
30 $data[] = $item;
31 }
32 }
33 else
34 {
35 $data = $items;
36 }
37
38 $this->id = $id;
39 $this->items = $data;
40 $this->totalCount = $totalCount;
41 }
42
46 public function getTotalCount()
47 {
48 if ($this->totalCount instanceof \Closure)
49 {
50 $this->calculatedTotalCount = call_user_func($this->totalCount);
51 }
52 else
53 {
54 $this->calculatedTotalCount = $this->totalCount;
55 }
56
57 return $this->calculatedTotalCount;
58 }
59
60
64 public function getId()
65 {
66 return $this->id;
67 }
68
72 public function getItems()
73 {
74 return $this->items;
75 }
76
84 public function getIterator()
85 {
86 return new \ArrayIterator($this->items);
87 }
88
103 public function offsetExists($offset)
104 {
105 return isset($this->items[$offset]) || array_key_exists($offset, $this->items);
106 }
107
119 #[\ReturnTypeWillChange]
120 public function offsetGet($offset)
121 {
122 if (isset($this->items[$offset]) || array_key_exists($offset, $this->items))
123 {
124 return $this->items[$offset];
125 }
126
127 return null;
128 }
129
144 public function offsetSet($offset, $value): void
145 {
146 if($offset === null)
147 {
148 $this->items[] = $value;
149 }
150 else
151 {
152 $this->items[$offset] = $value;
153 }
154 }
155
167 public function offsetUnset($offset): void
168 {
169 unset($this->items[$offset]);
170 }
171
179 public function jsonSerialize(): array
180 {
181 return $this->toArray();
182 }
183
184 public function toArray()
185 {
186 return [
187 $this->id => $this->items
188 ];
189 }
190}
__construct($id, $items, $totalCount)
Definition page.php:23