1 | <?php |
||
19 | abstract class AbstractResultsIterator implements \Countable, \Iterator |
||
20 | { |
||
21 | /** |
||
22 | * @var array Documents. |
||
23 | */ |
||
24 | protected $documents = []; |
||
25 | |||
26 | /** |
||
27 | * @var int |
||
28 | */ |
||
29 | private $count = 0; |
||
30 | |||
31 | /** |
||
32 | * @var array |
||
33 | */ |
||
34 | private $aggregations = []; |
||
35 | |||
36 | /** |
||
37 | * @var Converter |
||
38 | */ |
||
39 | private $converter; |
||
40 | |||
41 | /** |
||
42 | * @var Manager |
||
43 | */ |
||
44 | private $manager; |
||
45 | |||
46 | /** |
||
47 | * Elasticsearch manager configuration. |
||
48 | * |
||
49 | * @var array |
||
50 | */ |
||
51 | private $managerConfig = []; |
||
52 | |||
53 | /** |
||
54 | * @var string If value is not null then results are scrollable. |
||
55 | */ |
||
56 | private $scrollId; |
||
57 | |||
58 | /** |
||
59 | * @var string Scroll duration. |
||
60 | */ |
||
61 | private $scrollDuration; |
||
62 | |||
63 | /** |
||
64 | * Used to count iteration. |
||
65 | * |
||
66 | * @var int |
||
67 | */ |
||
68 | private $key = 0; |
||
69 | |||
70 | /** |
||
71 | * @param array $rawData |
||
72 | * @param Manager $manager |
||
73 | * @param array $scroll |
||
74 | */ |
||
75 | public function __construct( |
||
100 | |||
101 | /** |
||
102 | * Destructor. |
||
103 | */ |
||
104 | public function __destruct() |
||
111 | |||
112 | /** |
||
113 | * @return array |
||
114 | */ |
||
115 | protected function getAggregations() |
||
119 | |||
120 | /** |
||
121 | * @return Manager |
||
122 | */ |
||
123 | protected function getManager() |
||
127 | |||
128 | /** |
||
129 | * Returns total count of documents. |
||
130 | * |
||
131 | * @return int |
||
132 | */ |
||
133 | public function count() |
||
137 | |||
138 | /** |
||
139 | * Return the current element. |
||
140 | * |
||
141 | * @return mixed |
||
142 | */ |
||
143 | public function current() |
||
147 | |||
148 | /** |
||
149 | * Move forward to next element. |
||
150 | */ |
||
151 | public function next() |
||
155 | |||
156 | /** |
||
157 | * Return the key of the current element. |
||
158 | * |
||
159 | * @return mixed |
||
160 | */ |
||
161 | public function key() |
||
165 | |||
166 | /** |
||
167 | * Checks if current position is valid. |
||
168 | * |
||
169 | * @return bool |
||
170 | */ |
||
171 | public function valid() |
||
186 | |||
187 | /** |
||
188 | * Rewind the Iterator to the first element. |
||
189 | */ |
||
190 | public function rewind() |
||
194 | |||
195 | /** |
||
196 | * @return bool |
||
197 | */ |
||
198 | public function isScrollable() |
||
202 | |||
203 | /** |
||
204 | * @return array |
||
205 | */ |
||
206 | protected function getManagerConfig() |
||
210 | |||
211 | /** |
||
212 | * @return Converter |
||
213 | */ |
||
214 | protected function getConverter() |
||
218 | |||
219 | /** |
||
220 | * Gets document array from the container. |
||
221 | * |
||
222 | * @param mixed $key |
||
223 | * |
||
224 | * @return mixed |
||
225 | */ |
||
226 | protected function getDocument($key) |
||
234 | |||
235 | /** |
||
236 | * Checks whether document exists in the container. |
||
237 | * |
||
238 | * @param mixed $key |
||
239 | * |
||
240 | * @return bool |
||
241 | */ |
||
242 | protected function documentExists($key) |
||
246 | |||
247 | /** |
||
248 | * Advances key. |
||
249 | * |
||
250 | * @return $this |
||
251 | */ |
||
252 | protected function advanceKey() |
||
262 | |||
263 | /** |
||
264 | * Rewind's the iteration and returns first result. |
||
265 | * |
||
266 | * @return mixed|null |
||
267 | */ |
||
268 | public function first() |
||
274 | |||
275 | /** |
||
276 | * Advances scan page. |
||
277 | * |
||
278 | * @return $this |
||
279 | */ |
||
280 | protected function page() |
||
293 | |||
294 | /** |
||
295 | * Returns score of current hit. |
||
296 | * |
||
297 | * @return int |
||
298 | */ |
||
299 | public function getHitScore() |
||
311 | |||
312 | /** |
||
313 | * Converts raw array to document object or array, depends on iterator type. |
||
314 | * |
||
315 | * @param array $document |
||
316 | * |
||
317 | * @return object|array |
||
318 | */ |
||
319 | abstract protected function convertDocument(array $document); |
||
320 | } |
||
321 |