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 int |
||
71 | */ |
||
72 | protected $position = 0; |
||
73 | |||
74 | /** |
||
75 | * @var array |
||
76 | */ |
||
77 | protected $optionNames = [ |
||
78 | 'batchSize', |
||
79 | 'readPreference', |
||
80 | ]; |
||
81 | |||
82 | /** |
||
83 | * @return Cursor |
||
84 | */ |
||
85 | abstract protected function ensureCursor(); |
||
86 | |||
87 | /** |
||
88 | * @return array |
||
89 | */ |
||
90 | abstract protected function getCursorInfo(); |
||
91 | |||
92 | /** |
||
93 | * Create a new cursor |
||
94 | * @link http://www.php.net/manual/en/mongocursor.construct.php |
||
95 | * @param \MongoClient $connection Database connection. |
||
96 | * @param string $ns Full name of database and collection. |
||
97 | */ |
||
98 | 44 | public function __construct(\MongoClient $connection, $ns) |
|
113 | |||
114 | /** |
||
115 | * Returns the current element |
||
116 | * @link http://www.php.net/manual/en/mongocursor.current.php |
||
117 | * @return array |
||
118 | */ |
||
119 | 20 | public function current() |
|
132 | |||
133 | /** |
||
134 | * Returns the current result's _id |
||
135 | * @link http://www.php.net/manual/en/mongocursor.key.php |
||
136 | * @return string The current result's _id as a string. |
||
137 | */ |
||
138 | 12 | public function key() |
|
146 | |||
147 | /** |
||
148 | * Advances the cursor to the next result, and returns that result |
||
149 | * @link http://www.php.net/manual/en/mongocursor.next.php |
||
150 | * @throws \MongoConnectionException |
||
151 | * @throws \MongoCursorTimeoutException |
||
152 | * @return array Returns the next object |
||
153 | */ |
||
154 | 20 | public function next() |
|
166 | |||
167 | /** |
||
168 | * Returns the cursor to the beginning of the result set |
||
169 | * @throws \MongoConnectionException |
||
170 | * @throws \MongoCursorTimeoutException |
||
171 | * @return void |
||
172 | */ |
||
173 | 38 | public function rewind() |
|
181 | |||
182 | /** |
||
183 | * Checks if the cursor is reading a valid result. |
||
184 | * @link http://www.php.net/manual/en/mongocursor.valid.php |
||
185 | * @return boolean If the current result is not null. |
||
186 | */ |
||
187 | 36 | public function valid() |
|
195 | |||
196 | /** |
||
197 | * Limits the number of elements returned in one batch. |
||
198 | * |
||
199 | * @link http://docs.php.net/manual/en/mongocursor.batchsize.php |
||
200 | * @param int $batchSize The number of results to return per batch |
||
201 | * @return $this Returns this cursor. |
||
202 | */ |
||
203 | 1 | public function batchSize($batchSize) |
|
209 | |||
210 | /** |
||
211 | * Checks if there are documents that have not been sent yet from the database for this cursor |
||
212 | * @link http://www.php.net/manual/en/mongocursor.dead.php |
||
213 | * @return boolean Returns if there are more results that have not been sent to the client, yet. |
||
214 | */ |
||
215 | public function dead() |
||
219 | |||
220 | /** |
||
221 | * @return array |
||
222 | */ |
||
223 | 3 | public function info() |
|
227 | |||
228 | /** |
||
229 | * @link http://www.php.net/manual/en/mongocursor.setreadpreference.php |
||
230 | * @param string $readPreference |
||
231 | * @param array $tags |
||
232 | * @return $this Returns this cursor. |
||
233 | */ |
||
234 | 44 | public function setReadPreference($readPreference, $tags = null) |
|
240 | |||
241 | /** |
||
242 | * Sets a client-side timeout for this query |
||
243 | * @link http://www.php.net/manual/en/mongocursor.timeout.php |
||
244 | * @param int $ms The number of milliseconds for the cursor to wait for a response. By default, the cursor will wait forever. |
||
245 | * @return $this Returns this cursor |
||
246 | */ |
||
247 | public function timeout($ms) |
||
251 | |||
252 | /** |
||
253 | * Applies all options set on the cursor, overwriting any options that have already been set |
||
254 | * |
||
255 | * @param array $optionNames Array of option names to be applied (will be read from properties) |
||
256 | * @return array |
||
257 | */ |
||
258 | 41 | protected function getOptions($optionNames = null) |
|
279 | |||
280 | /** |
||
281 | * @return \Iterator |
||
282 | */ |
||
283 | 39 | protected function ensureIterator() |
|
293 | |||
294 | /** |
||
295 | * @param \Traversable $traversable |
||
296 | * @return \Generator |
||
297 | */ |
||
298 | 9 | protected function wrapTraversable(\Traversable $traversable) |
|
304 | |||
305 | /** |
||
306 | * @throws \MongoCursorException |
||
307 | */ |
||
308 | 19 | protected function errorIfOpened() |
|
316 | |||
317 | /** |
||
318 | * @return array |
||
319 | */ |
||
320 | 3 | protected function getIterationInfo() |
|
358 | |||
359 | /** |
||
360 | * @throws \Exception |
||
361 | */ |
||
362 | protected function notImplemented() |
||
366 | |||
367 | /** |
||
368 | * Clears the cursor |
||
369 | * |
||
370 | * This is generic but implemented as protected since it's only exposed in MongoCursor |
||
371 | */ |
||
372 | 39 | protected function reset() |
|
378 | |||
379 | /** |
||
380 | * @return array |
||
381 | */ |
||
382 | public function __sleep() |
||
386 | } |
||
387 |
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.