1 | <?php |
||
11 | abstract class EntityCollection implements \Countable, \Iterator |
||
12 | { |
||
13 | /** @var array */ |
||
14 | private $entities = array(); |
||
15 | /** @var bool */ |
||
16 | protected $allowEntitiesChildren; |
||
17 | |||
18 | /** |
||
19 | * @return string |
||
20 | */ |
||
21 | abstract public static function entityClass(): string; |
||
22 | |||
23 | /** |
||
24 | * Collection constructor. |
||
25 | * @param array $entities |
||
26 | * @param bool $allowEntitiesChildren |
||
27 | * @throws \Exception |
||
28 | */ |
||
29 | 62 | public function __construct(array $entities, bool $allowEntitiesChildren = false) |
|
41 | |||
42 | /** |
||
43 | * @param $entity |
||
44 | * @throws \Exception |
||
45 | */ |
||
46 | 54 | public function add($entity) |
|
54 | |||
55 | /** |
||
56 | * @param $key |
||
57 | * @param $entity |
||
58 | * @throws \Exception |
||
59 | */ |
||
60 | 5 | protected function set($key, $entity) |
|
68 | |||
69 | /** |
||
70 | * @param $entity |
||
71 | * @return bool |
||
72 | */ |
||
73 | 60 | public function isValid($entity): bool |
|
84 | |||
85 | /** |
||
86 | * @return array |
||
87 | */ |
||
88 | 7 | public function keys(): array |
|
92 | |||
93 | /** |
||
94 | * @return array |
||
95 | */ |
||
96 | 3 | public function values(): array |
|
100 | |||
101 | /** |
||
102 | * @return mixed |
||
103 | */ |
||
104 | 3 | public function first() |
|
108 | |||
109 | /** |
||
110 | * @return mixed |
||
111 | */ |
||
112 | 3 | public function last() |
|
116 | |||
117 | /** |
||
118 | * @return array |
||
119 | */ |
||
120 | 3 | public function toArray(): array |
|
124 | |||
125 | /** |
||
126 | * @param int $offset |
||
127 | * @param null $length |
||
128 | * @return static |
||
129 | * @throws \Exception |
||
130 | */ |
||
131 | 12 | public function slice(int $offset, $length = null) |
|
140 | |||
141 | /** |
||
142 | * @return mixed |
||
143 | */ |
||
144 | 11 | public function current() |
|
148 | |||
149 | /** |
||
150 | * @return mixed |
||
151 | */ |
||
152 | 13 | public function next() |
|
156 | |||
157 | /** |
||
158 | * @return mixed |
||
159 | */ |
||
160 | 9 | public function key() |
|
164 | |||
165 | /** |
||
166 | * @return bool |
||
167 | */ |
||
168 | 4 | public function valid(): bool |
|
172 | |||
173 | 4 | public function rewind() |
|
177 | |||
178 | /** |
||
179 | * @return int |
||
180 | */ |
||
181 | 12 | public function count(): int |
|
185 | |||
186 | /** |
||
187 | * @return \Exception |
||
188 | */ |
||
189 | 7 | public static function customEmptyException(): \Exception |
|
193 | |||
194 | /** |
||
195 | * @return \Exception |
||
196 | */ |
||
197 | 3 | public static function customInvalidEntityException(): \Exception |
|
201 | } |
||
202 |