1 | <?php |
||
25 | abstract class AbstractCursor |
||
26 | { |
||
27 | use ReadPreference; |
||
28 | |||
29 | /** |
||
30 | * @var int |
||
31 | */ |
||
32 | protected $batchSize; |
||
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 \IteratorIterator |
||
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 array |
||
71 | */ |
||
72 | protected $optionNames = [ |
||
73 | 'batchSize', |
||
74 | 'readPreference', |
||
75 | ]; |
||
76 | |||
77 | /** |
||
78 | * @return Cursor |
||
79 | */ |
||
80 | abstract protected function ensureCursor(); |
||
81 | |||
82 | /** |
||
83 | * @return array |
||
84 | */ |
||
85 | abstract protected function getCursorInfo(); |
||
86 | |||
87 | /** |
||
88 | * Create a new cursor |
||
89 | * @link http://www.php.net/manual/en/mongocursor.construct.php |
||
90 | * @param \MongoClient $connection Database connection. |
||
91 | * @param string $ns Full name of database and collection. |
||
92 | */ |
||
93 | 42 | public function __construct(\MongoClient $connection, $ns) |
|
108 | |||
109 | /** |
||
110 | * Returns the current element |
||
111 | * @link http://www.php.net/manual/en/mongocursor.current.php |
||
112 | * @return array |
||
113 | */ |
||
114 | 19 | public function current() |
|
124 | |||
125 | /** |
||
126 | * Returns the current result's _id |
||
127 | * @link http://www.php.net/manual/en/mongocursor.key.php |
||
128 | * @return string The current result's _id as a string. |
||
129 | */ |
||
130 | 10 | public function key() |
|
134 | |||
135 | /** |
||
136 | * Advances the cursor to the next result, and returns that result |
||
137 | * @link http://www.php.net/manual/en/mongocursor.next.php |
||
138 | * @throws \MongoConnectionException |
||
139 | * @throws \MongoCursorTimeoutException |
||
140 | * @return array Returns the next object |
||
141 | */ |
||
142 | 19 | public function next() |
|
153 | |||
154 | /** |
||
155 | * Returns the cursor to the beginning of the result set |
||
156 | * @throws \MongoConnectionException |
||
157 | * @throws \MongoCursorTimeoutException |
||
158 | * @return void |
||
159 | */ |
||
160 | 36 | public function rewind() |
|
167 | |||
168 | /** |
||
169 | * Checks if the cursor is reading a valid result. |
||
170 | * @link http://www.php.net/manual/en/mongocursor.valid.php |
||
171 | * @return boolean If the current result is not null. |
||
172 | */ |
||
173 | 34 | public function valid() |
|
177 | |||
178 | /** |
||
179 | * Limits the number of elements returned in one batch. |
||
180 | * |
||
181 | * @link http://docs.php.net/manual/en/mongocursor.batchsize.php |
||
182 | * @param int $batchSize The number of results to return per batch |
||
183 | * @return $this Returns this cursor. |
||
184 | */ |
||
185 | 1 | public function batchSize($batchSize) |
|
191 | |||
192 | /** |
||
193 | * Checks if there are documents that have not been sent yet from the database for this cursor |
||
194 | * @link http://www.php.net/manual/en/mongocursor.dead.php |
||
195 | * @return boolean Returns if there are more results that have not been sent to the client, yet. |
||
196 | */ |
||
197 | public function dead() |
||
201 | |||
202 | /** |
||
203 | * @return array |
||
204 | */ |
||
205 | 2 | public function info() |
|
209 | |||
210 | /** |
||
211 | * @link http://www.php.net/manual/en/mongocursor.setreadpreference.php |
||
212 | * @param string $readPreference |
||
213 | * @param array $tags |
||
214 | * @return $this Returns this cursor. |
||
215 | */ |
||
216 | 42 | public function setReadPreference($readPreference, $tags = null) |
|
222 | |||
223 | /** |
||
224 | * Sets a client-side timeout for this query |
||
225 | * @link http://www.php.net/manual/en/mongocursor.timeout.php |
||
226 | * @param int $ms The number of milliseconds for the cursor to wait for a response. By default, the cursor will wait forever. |
||
227 | * @return $this Returns this cursor |
||
228 | */ |
||
229 | public function timeout($ms) |
||
233 | |||
234 | /** |
||
235 | * Applies all options set on the cursor, overwriting any options that have already been set |
||
236 | * |
||
237 | * @param array $optionNames Array of option names to be applied (will be read from properties) |
||
238 | * @return array |
||
239 | */ |
||
240 | 39 | protected function getOptions($optionNames = null) |
|
261 | |||
262 | /** |
||
263 | * @return \Generator |
||
264 | */ |
||
265 | 37 | protected function ensureIterator() |
|
275 | |||
276 | /** |
||
277 | * @param \Traversable $traversable |
||
278 | * @return \Generator |
||
279 | */ |
||
280 | 35 | private function wrapTraversable(\Traversable $traversable) |
|
286 | |||
287 | /** |
||
288 | * @throws \MongoCursorException |
||
289 | */ |
||
290 | 15 | protected function errorIfOpened() |
|
298 | |||
299 | /** |
||
300 | * @return array |
||
301 | */ |
||
302 | 2 | protected function getIterationInfo() |
|
339 | |||
340 | /** |
||
341 | * @throws \Exception |
||
342 | */ |
||
343 | protected function notImplemented() |
||
347 | |||
348 | /** |
||
349 | * Clears the cursor |
||
350 | * |
||
351 | * This is generic but implemented as protected since it's only exposed in MongoCursor |
||
352 | */ |
||
353 | 37 | protected function reset() |
|
359 | } |
||
360 |
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.