1 | <?php |
||
20 | abstract class AbstractResultsIterator implements \ArrayAccess, \Countable, \Iterator |
||
21 | { |
||
22 | /** |
||
23 | * @var array Documents. |
||
24 | */ |
||
25 | protected $documents = []; |
||
26 | |||
27 | /** |
||
28 | * @var int |
||
29 | */ |
||
30 | private $count = 0; |
||
31 | |||
32 | /** |
||
33 | * @var array |
||
34 | */ |
||
35 | private $aggregations = []; |
||
36 | |||
37 | /** |
||
38 | * @var Converter |
||
39 | */ |
||
40 | private $converter; |
||
41 | |||
42 | /** |
||
43 | * @var Repository |
||
44 | */ |
||
45 | private $repository; |
||
46 | |||
47 | /** |
||
48 | * Elasticsearch manager configuration. |
||
49 | * |
||
50 | * @var array |
||
51 | */ |
||
52 | private $managerConfig = []; |
||
53 | |||
54 | /** |
||
55 | * @var string If value is not null then results are scrollable. |
||
56 | */ |
||
57 | private $scrollId; |
||
58 | |||
59 | /** |
||
60 | * @var string Scroll duration. |
||
61 | */ |
||
62 | private $scrollDuration; |
||
63 | |||
64 | /** |
||
65 | * Used to count iteration. |
||
66 | * |
||
67 | * @var int |
||
68 | */ |
||
69 | private $key = 0; |
||
70 | |||
71 | /** |
||
72 | * @param array $rawData |
||
73 | * @param Repository $repository |
||
74 | * @param array $scroll |
||
75 | */ |
||
76 | public function __construct( |
||
101 | |||
102 | /** |
||
103 | * @return array |
||
104 | */ |
||
105 | protected function getAggregations() |
||
109 | |||
110 | /** |
||
111 | * @return Repository |
||
112 | */ |
||
113 | public function getRepository() |
||
117 | |||
118 | /** |
||
119 | * {@inheritdoc} |
||
120 | */ |
||
121 | public function offsetExists($offset) |
||
125 | |||
126 | /** |
||
127 | * {@inheritdoc} |
||
128 | */ |
||
129 | public function offsetGet($offset) |
||
133 | |||
134 | /** |
||
135 | * {@inheritdoc} |
||
136 | */ |
||
137 | public function offsetSet($offset, $value) |
||
141 | |||
142 | /** |
||
143 | * {@inheritdoc} |
||
144 | */ |
||
145 | public function offsetUnset($offset) |
||
149 | |||
150 | /** |
||
151 | * Returns total count of documents. |
||
152 | * |
||
153 | * @return int |
||
154 | */ |
||
155 | public function count() |
||
159 | |||
160 | /** |
||
161 | * Return the current element. |
||
162 | * |
||
163 | * @return mixed |
||
164 | */ |
||
165 | public function current() |
||
169 | |||
170 | /** |
||
171 | * Move forward to next element. |
||
172 | */ |
||
173 | public function next() |
||
177 | |||
178 | /** |
||
179 | * Return the key of the current element. |
||
180 | * |
||
181 | * @return mixed |
||
182 | */ |
||
183 | public function key() |
||
187 | |||
188 | /** |
||
189 | * Checks if current position is valid. |
||
190 | * |
||
191 | * @return bool |
||
192 | */ |
||
193 | public function valid() |
||
204 | |||
205 | /** |
||
206 | * Rewind the Iterator to the first element. |
||
207 | */ |
||
208 | public function rewind() |
||
212 | |||
213 | /** |
||
214 | * @return bool |
||
215 | */ |
||
216 | public function isScrollable() |
||
220 | |||
221 | /** |
||
222 | * @return array |
||
223 | */ |
||
224 | protected function getManagerConfig() |
||
228 | |||
229 | /** |
||
230 | * @return Converter |
||
231 | */ |
||
232 | protected function getConverter() |
||
236 | |||
237 | /** |
||
238 | * Gets document array from the container. |
||
239 | * |
||
240 | * @param mixed $key |
||
241 | * |
||
242 | * @return mixed |
||
243 | */ |
||
244 | protected function getDocument($key) |
||
252 | |||
253 | /** |
||
254 | * Checks whether document exists in the container. |
||
255 | * |
||
256 | * @param mixed $key |
||
257 | * |
||
258 | * @return bool |
||
259 | */ |
||
260 | protected function documentExists($key) |
||
264 | |||
265 | /** |
||
266 | * Advances key. |
||
267 | * |
||
268 | * @return $this |
||
269 | */ |
||
270 | protected function advanceKey() |
||
280 | |||
281 | /** |
||
282 | * Rewind's the iteration and returns first result. |
||
283 | * |
||
284 | * @return mixed|null |
||
285 | */ |
||
286 | public function first() |
||
292 | |||
293 | /** |
||
294 | * Advances scan page. |
||
295 | * |
||
296 | * @return $this |
||
297 | */ |
||
298 | protected function page() |
||
311 | |||
312 | /** |
||
313 | * Converts raw array to document object or array, depends on iterator type. |
||
314 | * |
||
315 | * @param array $document |
||
316 | * |
||
317 | * @return DocumentInterface|array |
||
318 | */ |
||
319 | abstract protected function convertDocument(array $document); |
||
320 | } |
||
321 |