1 | <?php |
||
25 | abstract class AbstractCursor |
||
26 | { |
||
27 | use ReadPreference; |
||
28 | |||
29 | /** |
||
30 | * @var int |
||
31 | */ |
||
32 | protected $batchSize = 0; |
||
33 | |||
34 | /** |
||
35 | * @var Collection |
||
36 | */ |
||
37 | protected $collection; |
||
38 | |||
39 | /** |
||
40 | * @var \MongoClient |
||
41 | */ |
||
42 | protected $connection; |
||
43 | |||
44 | /** |
||
45 | * @var Cursor |
||
46 | */ |
||
47 | protected $cursor; |
||
48 | |||
49 | /** |
||
50 | * @var \MongoDB\Database |
||
51 | */ |
||
52 | protected $db; |
||
53 | |||
54 | /** |
||
55 | * @var \Iterator |
||
56 | */ |
||
57 | protected $iterator; |
||
58 | |||
59 | /** |
||
60 | * @var string |
||
61 | */ |
||
62 | protected $ns; |
||
63 | |||
64 | /** |
||
65 | * @var bool |
||
66 | */ |
||
67 | protected $startedIterating = false; |
||
68 | |||
69 | /** |
||
70 | * @var bool |
||
71 | */ |
||
72 | protected $cursorNeedsAdvancing = true; |
||
73 | |||
74 | /** |
||
75 | * @var mixed |
||
76 | */ |
||
77 | private $current = null; |
||
78 | |||
79 | /** |
||
80 | * @var mixed |
||
81 | */ |
||
82 | private $key = null; |
||
83 | |||
84 | /** |
||
85 | * @var mixed |
||
86 | */ |
||
87 | private $valid = false; |
||
88 | |||
89 | /** |
||
90 | * @var int |
||
91 | */ |
||
92 | protected $position = 0; |
||
93 | |||
94 | /** |
||
95 | * @var array |
||
96 | */ |
||
97 | protected $optionNames = [ |
||
98 | 'batchSize', |
||
99 | 'readPreference', |
||
100 | ]; |
||
101 | |||
102 | /** |
||
103 | * @return Cursor |
||
104 | */ |
||
105 | abstract protected function ensureCursor(); |
||
106 | |||
107 | /** |
||
108 | * @return array |
||
109 | */ |
||
110 | abstract protected function getCursorInfo(); |
||
111 | |||
112 | /** |
||
113 | * Create a new cursor |
||
114 | * @link http://www.php.net/manual/en/mongocursor.construct.php |
||
115 | * @param \MongoClient $connection Database connection. |
||
116 | * @param string $ns Full name of database and collection. |
||
117 | */ |
||
118 | 51 | public function __construct(\MongoClient $connection, $ns) |
|
133 | |||
134 | /** |
||
135 | * Returns the current element |
||
136 | * @link http://www.php.net/manual/en/mongocursor.current.php |
||
137 | * @return array |
||
138 | */ |
||
139 | 23 | public function current() |
|
143 | |||
144 | /** |
||
145 | * Returns the current result's _id |
||
146 | * @link http://www.php.net/manual/en/mongocursor.key.php |
||
147 | * @return string The current result's _id as a string. |
||
148 | */ |
||
149 | 14 | public function key() |
|
153 | |||
154 | /** |
||
155 | * Advances the cursor to the next result, and returns that result |
||
156 | * @link http://www.php.net/manual/en/mongocursor.next.php |
||
157 | * @throws \MongoConnectionException |
||
158 | * @throws \MongoCursorTimeoutException |
||
159 | * @return array Returns the next object |
||
160 | */ |
||
161 | 24 | public function next() |
|
177 | |||
178 | /** |
||
179 | * Returns the cursor to the beginning of the result set |
||
180 | * @throws \MongoConnectionException |
||
181 | * @throws \MongoCursorTimeoutException |
||
182 | * @return void |
||
183 | */ |
||
184 | 42 | public function rewind() |
|
193 | |||
194 | /** |
||
195 | * Checks if the cursor is reading a valid result. |
||
196 | * @link http://www.php.net/manual/en/mongocursor.valid.php |
||
197 | * @return boolean If the current result is not null. |
||
198 | */ |
||
199 | 40 | public function valid() |
|
203 | |||
204 | /** |
||
205 | * Limits the number of elements returned in one batch. |
||
206 | * |
||
207 | * @link http://docs.php.net/manual/en/mongocursor.batchsize.php |
||
208 | * @param int $batchSize The number of results to return per batch |
||
209 | * @return $this Returns this cursor. |
||
210 | */ |
||
211 | 1 | public function batchSize($batchSize) |
|
217 | |||
218 | /** |
||
219 | * Checks if there are documents that have not been sent yet from the database for this cursor |
||
220 | * @link http://www.php.net/manual/en/mongocursor.dead.php |
||
221 | * @return boolean Returns if there are more results that have not been sent to the client, yet. |
||
222 | */ |
||
223 | public function dead() |
||
227 | |||
228 | /** |
||
229 | * @return array |
||
230 | */ |
||
231 | 3 | public function info() |
|
235 | |||
236 | /** |
||
237 | * @link http://www.php.net/manual/en/mongocursor.setreadpreference.php |
||
238 | * @param string $readPreference |
||
239 | * @param array $tags |
||
240 | * @return $this Returns this cursor. |
||
241 | */ |
||
242 | 51 | public function setReadPreference($readPreference, $tags = null) |
|
248 | |||
249 | /** |
||
250 | * Sets a client-side timeout for this query |
||
251 | * @link http://www.php.net/manual/en/mongocursor.timeout.php |
||
252 | * @param int $ms The number of milliseconds for the cursor to wait for a response. By default, the cursor will wait forever. |
||
253 | * @return $this Returns this cursor |
||
254 | */ |
||
255 | public function timeout($ms) |
||
260 | |||
261 | /** |
||
262 | * Applies all options set on the cursor, overwriting any options that have already been set |
||
263 | * |
||
264 | * @param array $optionNames Array of option names to be applied (will be read from properties) |
||
265 | * @return array |
||
266 | */ |
||
267 | 45 | protected function getOptions($optionNames = null) |
|
288 | |||
289 | /** |
||
290 | * @return \Iterator |
||
291 | */ |
||
292 | 43 | protected function ensureIterator() |
|
302 | |||
303 | /** |
||
304 | * @param \Traversable $traversable |
||
305 | * @return \Generator |
||
306 | */ |
||
307 | 11 | protected function wrapTraversable(\Traversable $traversable) |
|
313 | |||
314 | /** |
||
315 | * @throws \MongoCursorException |
||
316 | */ |
||
317 | 21 | protected function errorIfOpened() |
|
325 | |||
326 | /** |
||
327 | * @return array |
||
328 | */ |
||
329 | 3 | protected function getIterationInfo() |
|
367 | |||
368 | /** |
||
369 | * @throws \Exception |
||
370 | */ |
||
371 | protected function notImplemented() |
||
375 | |||
376 | /** |
||
377 | * Clears the cursor |
||
378 | * |
||
379 | * This is generic but implemented as protected since it's only exposed in MongoCursor |
||
380 | */ |
||
381 | 43 | protected function reset() |
|
388 | |||
389 | /** |
||
390 | * @return array |
||
391 | */ |
||
392 | 3 | public function __sleep() |
|
396 | |||
397 | /** |
||
398 | * Stores the current cursor element. |
||
399 | * |
||
400 | * This is necessary because hasNext() might advance the iterator but we still |
||
401 | * need to be able to return the current object. |
||
402 | */ |
||
403 | 43 | private function storeIteratorState() |
|
422 | } |
||
423 |
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.