Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
collectionbase.php
1<?php
2
4
6
7Loc::loadMessages(__FILE__);
8
13abstract class CollectionBase
14 implements \ArrayAccess, \Countable, \IteratorAggregate
15{
17 protected $collection = array();
18
22 public function getIterator(): \Traversable
23 {
24 return new \ArrayIterator($this->collection);
25 }
26
27
31 public function offsetExists($offset): bool
32 {
33 return isset($this->collection[$offset]) || array_key_exists($offset, $this->collection);
34 }
35
39 #[\ReturnTypeWillChange]
40 public function offsetGet($offset)
41 {
42 if (isset($this->collection[$offset]) || array_key_exists($offset, $this->collection))
43 {
44 return $this->collection[$offset];
45 }
46
47 return null;
48 }
49
53 public function offsetSet($offset, $value): void
54 {
55 if($offset === null)
56 {
57 $this->collection[] = $value;
58 }
59 else
60 {
61 $this->collection[$offset] = $value;
62 }
63 }
64
68 public function offsetUnset($offset): void
69 {
70 unset($this->collection[$offset]);
71 }
72
76 public function count(): int
77 {
78 return count($this->collection);
79 }
80
84 public function current()
85 {
86 return current($this->collection);
87 }
88
92 public function next()
93 {
94 return next($this->collection);
95 }
96
100 public function key()
101 {
102 return key($this->collection);
103 }
104
108 public function valid()
109 {
110 $key = $this->key();
111 return $key !== null;
112 }
113
117 public function rewind()
118 {
119 return reset($this->collection);
120 }
121
127 public function isEmpty()
128 {
129 return empty($this->collection);
130 }
131
132 public function toArray()
133 {
134 $result = [];
135
136 foreach ($this->collection as $entity)
137 {
138 $result[] = $entity->toArray();
139 }
140
141 return $result;
142 }
143}
static loadMessages($file)
Definition loc.php:64