Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
collection.php
1<?php
2
4
11 implements \ArrayAccess, \Countable, \Iterator
12{
13 protected $items = [];
14
18 public function __construct(array $items = [])
19 {
20 $this->setItems($items);
21 }
22
26 public function setItems(array $items): void
27 {
28 foreach($items as $item)
29 {
30 $this->addItem($item);
31 }
32 }
33
37 public function getItems(): array
38 {
39 return $this->items;
40 }
41
46 public function offsetSet($offset, $value): void
47 {
48 if ($offset === null)
49 {
50 $this->items[] = $value;
51 }
52 else
53 {
54 $this->items[$offset] = $value;
55 }
56 }
57
62 public function offsetExists($offset): bool
63 {
64 return isset($this->items[$offset]);
65 }
66
70 public function offsetUnset($offset): void
71 {
72 unset($this->items[$offset]);
73 }
74
79 #[\ReturnTypeWillChange]
80 public function offsetGet($offset)
81 {
82 return isset($this->items[$offset]) ? $this->items[$offset] : null;
83 }
84
88 public function count(): int
89 {
90 return count($this->items);
91 }
92
93 public function rewind(): void
94 {
95 reset($this->items);
96 }
97
101 #[\ReturnTypeWillChange]
102 public function current()
103 {
104 return current($this->items);
105 }
106
110 #[\ReturnTypeWillChange]
111 public function key()
112 {
113 return key($this->items);
114 }
115
116 public function next(): void
117 {
118 next($this->items);
119 }
120
124 public function valid(): bool
125 {
126 return $this->current() !== false && isset($this->items[$this->key()]);
127 }
128
129 public function clear()
130 {
131 $this->items = [];
132 }
133
138 public function addItem($item): int
139 {
140 $this->items[] = $item;
141 end($this->items);
142 return key($this->items);
143 }
144}