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 | */ |
||
28 | 66 | public function __construct(array $entities = array(), bool $allowEntitiesChildren = false) |
|
36 | |||
37 | /** |
||
38 | * @param $entity |
||
39 | * @throws \Exception |
||
40 | */ |
||
41 | 103 | public function add($entity) |
|
49 | |||
50 | /** |
||
51 | * @param $key |
||
52 | * @param $entity |
||
53 | * @throws \Exception |
||
54 | */ |
||
55 | 5 | protected function set($key, $entity) |
|
63 | |||
64 | /** |
||
65 | * @param $entity |
||
66 | * @return bool |
||
67 | */ |
||
68 | 109 | public function isValid($entity): bool |
|
79 | |||
80 | /** |
||
81 | * @return bool |
||
82 | */ |
||
83 | 7 | public function isEmpty(): bool |
|
87 | |||
88 | /** |
||
89 | * @return array |
||
90 | */ |
||
91 | 11 | public function keys(): array |
|
95 | |||
96 | /** |
||
97 | * @return array |
||
98 | */ |
||
99 | 7 | public function values(): array |
|
103 | |||
104 | /** |
||
105 | * @return mixed |
||
106 | */ |
||
107 | 7 | public function first() |
|
111 | |||
112 | /** |
||
113 | * @return mixed |
||
114 | */ |
||
115 | 7 | public function last() |
|
119 | |||
120 | /** |
||
121 | * @return array |
||
122 | */ |
||
123 | 19 | public function toArray(): array |
|
127 | |||
128 | /** |
||
129 | * @param int $offset |
||
130 | * @param null $length |
||
131 | * @return static |
||
132 | */ |
||
133 | 16 | public function slice(int $offset, $length = null) |
|
139 | |||
140 | /** |
||
141 | * @return mixed |
||
142 | */ |
||
143 | 21 | public function current() |
|
147 | |||
148 | /** |
||
149 | * @return mixed |
||
150 | */ |
||
151 | 27 | public function next() |
|
155 | |||
156 | /** |
||
157 | * @return mixed |
||
158 | */ |
||
159 | 19 | public function key() |
|
163 | |||
164 | /** |
||
165 | * @return bool |
||
166 | */ |
||
167 | 8 | public function valid(): bool |
|
171 | |||
172 | 8 | public function rewind() |
|
176 | |||
177 | /** |
||
178 | * @return int |
||
179 | */ |
||
180 | 39 | public function count(): int |
|
184 | |||
185 | /** |
||
186 | * @return \Exception |
||
187 | */ |
||
188 | 4 | public static function customInvalidEntityException(): \Exception |
|
192 | } |
||
193 |