1 | <?php |
||
26 | class CompositionIterator implements Iterator, Countable |
||
27 | { |
||
28 | private $model = null; |
||
29 | |||
30 | private $direct = false; |
||
31 | |||
32 | private $types = []; |
||
33 | |||
34 | /** |
||
35 | * Models holder |
||
36 | * @var null|AnnotatedInterface[] |
||
37 | */ |
||
38 | private $models = null; |
||
39 | |||
40 | private $pointer = 0; |
||
41 | |||
42 | private $fieldNames = []; |
||
43 | |||
44 | 60 | public function __construct(AnnotatedInterface $model) |
|
48 | |||
49 | /** |
||
50 | * Limit results to only direct descendants. |
||
51 | * @return $this |
||
52 | */ |
||
53 | 6 | public function direct() |
|
58 | |||
59 | /** |
||
60 | * Limit results to only to the type provided. |
||
61 | * |
||
62 | * The `$type` should be class or interface name |
||
63 | * or object instance. |
||
64 | * |
||
65 | * Repeated calls will add types uniquely. |
||
66 | * |
||
67 | * @param $type string|object |
||
68 | * @param $include boolean Whether to include this type or skip |
||
69 | * @return $this |
||
70 | */ |
||
71 | 58 | public function ofType($type, $include = true) |
|
82 | |||
83 | /** |
||
84 | * Get currently iterated over field name, |
||
85 | * which have models |
||
86 | * @return string |
||
87 | */ |
||
88 | public function getCurrentField() |
||
96 | |||
97 | 60 | private function init() |
|
105 | |||
106 | 60 | private function iterate($model) |
|
153 | |||
154 | 18 | private function skip($model) |
|
168 | |||
169 | /** |
||
170 | * Whether to include `$model` in result |
||
171 | * @param $model |
||
172 | * @return bool |
||
173 | */ |
||
174 | 18 | private function doInclude($model) |
|
192 | |||
193 | 18 | private function recurse() |
|
197 | |||
198 | 14 | public function current() |
|
203 | |||
204 | 14 | public function next() |
|
209 | |||
210 | public function key() |
||
215 | |||
216 | 60 | public function valid() |
|
221 | |||
222 | 60 | public function rewind() |
|
227 | |||
228 | 5 | public function count() |
|
233 | |||
234 | |||
235 | } |