| 1 | <?php |
||
| 27 | class MongoCursor extends AbstractCursor implements Iterator |
||
|
1 ignored issue
–
show
|
|||
| 28 | { |
||
| 29 | /** |
||
| 30 | * @var bool |
||
| 31 | */ |
||
| 32 | public static $slaveOkay = false; |
||
| 33 | |||
| 34 | /** |
||
| 35 | * @var int |
||
| 36 | */ |
||
| 37 | public static $timeout = 30000; |
||
| 38 | |||
| 39 | /** |
||
| 40 | * @var array |
||
| 41 | */ |
||
| 42 | protected $optionNames = [ |
||
| 43 | 'allowPartialResults', |
||
| 44 | 'batchSize', |
||
| 45 | 'cursorType', |
||
| 46 | 'limit', |
||
| 47 | 'maxTimeMS', |
||
| 48 | 'modifiers', |
||
| 49 | 'noCursorTimeout', |
||
| 50 | 'projection', |
||
| 51 | 'readPreference', |
||
| 52 | 'skip', |
||
| 53 | 'sort', |
||
| 54 | ]; |
||
| 55 | |||
| 56 | /** |
||
| 57 | * @var array |
||
| 58 | */ |
||
| 59 | protected $projection; |
||
| 60 | |||
| 61 | /** |
||
| 62 | * @var array |
||
| 63 | */ |
||
| 64 | protected $query; |
||
| 65 | |||
| 66 | protected $allowPartialResults; |
||
| 67 | protected $awaitData; |
||
| 68 | protected $flags = 0; |
||
| 69 | protected $hint; |
||
| 70 | protected $limit; |
||
| 71 | protected $maxTimeMS; |
||
| 72 | protected $noCursorTimeout; |
||
| 73 | protected $options = []; |
||
| 74 | protected $skip; |
||
| 75 | protected $snapshot; |
||
| 76 | protected $sort; |
||
| 77 | protected $tailable; |
||
| 78 | |||
| 79 | /** |
||
| 80 | * Create a new cursor |
||
| 81 | * @link http://www.php.net/manual/en/mongocursor.construct.php |
||
| 82 | * @param MongoClient $connection Database connection. |
||
| 83 | * @param string $ns Full name of database and collection. |
||
| 84 | * @param array $query Database query. |
||
| 85 | * @param array $fields Fields to return. |
||
| 86 | */ |
||
| 87 | public function __construct(MongoClient $connection, $ns, array $query = array(), array $fields = array()) |
||
| 94 | |||
| 95 | /** |
||
| 96 | * Adds a top-level key/value pair to a query |
||
| 97 | * @link http://www.php.net/manual/en/mongocursor.addoption.php |
||
| 98 | * @param string $key Fieldname to add. |
||
| 99 | * @param mixed $value Value to add. |
||
| 100 | * @throws MongoCursorException |
||
| 101 | * @return MongoCursor Returns this cursor |
||
| 102 | */ |
||
| 103 | public function addOption($key, $value) |
||
| 110 | |||
| 111 | /** |
||
| 112 | * (PECL mongo >= 1.2.11)<br/> |
||
| 113 | * Sets whether this cursor will wait for a while for a tailable cursor to return more data |
||
| 114 | * @param bool $wait [optional] <p>If the cursor should wait for more data to become available.</p> |
||
| 115 | * @return MongoCursor Returns this cursor. |
||
| 116 | */ |
||
| 117 | public function awaitData($wait = true) |
||
| 124 | |||
| 125 | |||
| 126 | /** |
||
| 127 | * Counts the number of results for this query |
||
| 128 | * @link http://www.php.net/manual/en/mongocursor.count.php |
||
| 129 | * @param bool $foundOnly Send cursor limit and skip information to the count function, if applicable. |
||
| 130 | * @return int The number of documents returned by this cursor's query. |
||
| 131 | */ |
||
| 132 | public function count($foundOnly = false) |
||
| 154 | |||
| 155 | /** |
||
| 156 | * Execute the query |
||
| 157 | * @link http://www.php.net/manual/en/mongocursor.doquery.php |
||
| 158 | * @throws MongoConnectionException if it cannot reach the database. |
||
| 159 | * @return void |
||
| 160 | */ |
||
| 161 | protected function doQuery() |
||
| 173 | |||
| 174 | /** |
||
| 175 | * Return an explanation of the query, often useful for optimization and debugging |
||
| 176 | * @link http://www.php.net/manual/en/mongocursor.explain.php |
||
| 177 | * @return array Returns an explanation of the query. |
||
| 178 | */ |
||
| 179 | public function explain() |
||
| 183 | |||
| 184 | /** |
||
| 185 | * Sets the fields for a query |
||
| 186 | * @link http://www.php.net/manual/en/mongocursor.fields.php |
||
| 187 | * @param array $f Fields to return (or not return). |
||
| 188 | * @throws MongoCursorException |
||
| 189 | * @return MongoCursor |
||
| 190 | */ |
||
| 191 | public function fields(array $f) |
||
| 198 | |||
| 199 | /** |
||
| 200 | * Return the next object to which this cursor points, and advance the cursor |
||
| 201 | * @link http://www.php.net/manual/en/mongocursor.getnext.php |
||
| 202 | * @throws MongoConnectionException |
||
| 203 | * @throws MongoCursorTimeoutException |
||
| 204 | * @return array Returns the next object |
||
| 205 | */ |
||
| 206 | public function getNext() |
||
| 212 | |||
| 213 | /** |
||
| 214 | * Checks if there are any more elements in this cursor |
||
| 215 | * @link http://www.php.net/manual/en/mongocursor.hasnext.php |
||
| 216 | * @throws MongoConnectionException |
||
| 217 | * @throws MongoCursorTimeoutException |
||
| 218 | * @return bool Returns true if there is another element |
||
| 219 | */ |
||
| 220 | public function hasNext() |
||
| 225 | |||
| 226 | /** |
||
| 227 | * Gives the database a hint about the query |
||
| 228 | * @link http://www.php.net/manual/en/mongocursor.hint.php |
||
| 229 | * @param array|string $keyPattern Indexes to use for the query. |
||
| 230 | * @throws MongoCursorException |
||
| 231 | * @return MongoCursor Returns this cursor |
||
| 232 | */ |
||
| 233 | public function hint($keyPattern) |
||
| 240 | |||
| 241 | /** |
||
| 242 | * Sets whether this cursor will timeout |
||
| 243 | * @link http://www.php.net/manual/en/mongocursor.immortal.php |
||
| 244 | * @param bool $liveForever If the cursor should be immortal. |
||
| 245 | * @throws MongoCursorException |
||
| 246 | * @return MongoCursor Returns this cursor |
||
| 247 | */ |
||
| 248 | public function immortal($liveForever = true) |
||
| 255 | |||
| 256 | /** |
||
| 257 | * Limits the number of results returned |
||
| 258 | * @link http://www.php.net/manual/en/mongocursor.limit.php |
||
| 259 | * @param int $num The number of results to return. |
||
| 260 | * @throws MongoCursorException |
||
| 261 | * @return MongoCursor Returns this cursor |
||
| 262 | */ |
||
| 263 | public function limit($num) |
||
| 270 | |||
| 271 | /** |
||
| 272 | * @param int $ms |
||
| 273 | * @return $this |
||
| 274 | * @throws MongoCursorException |
||
| 275 | */ |
||
| 276 | public function maxTimeMS($ms) |
||
| 283 | |||
| 284 | /** |
||
| 285 | * @link http://www.php.net/manual/en/mongocursor.partial.php |
||
| 286 | * @param bool $okay [optional] <p>If receiving partial results is okay.</p> |
||
| 287 | * @return MongoCursor Returns this cursor. |
||
| 288 | */ |
||
| 289 | public function partial($okay = true) |
||
| 295 | |||
| 296 | /** |
||
| 297 | * Clears the cursor |
||
| 298 | * @link http://www.php.net/manual/en/mongocursor.reset.php |
||
| 299 | * @return void |
||
| 300 | */ |
||
| 301 | public function reset() |
||
| 305 | |||
| 306 | /** |
||
| 307 | * @link http://www.php.net/manual/en/mongocursor.setflag.php |
||
| 308 | * @param int $flag |
||
| 309 | * @param bool $set |
||
| 310 | * @return MongoCursor |
||
| 311 | */ |
||
| 312 | public function setFlag($flag, $set = true) |
||
| 316 | |||
| 317 | /** |
||
| 318 | * Skips a number of results |
||
| 319 | * @link http://www.php.net/manual/en/mongocursor.skip.php |
||
| 320 | * @param int $num The number of results to skip. |
||
| 321 | * @throws MongoCursorException |
||
| 322 | * @return MongoCursor Returns this cursor |
||
| 323 | */ |
||
| 324 | public function skip($num) |
||
| 331 | |||
| 332 | /** |
||
| 333 | * Sets whether this query can be done on a slave |
||
| 334 | * This method will override the static class variable slaveOkay. |
||
| 335 | * @link http://www.php.net/manual/en/mongocursor.slaveOkay.php |
||
| 336 | * @param boolean $okay If it is okay to query the slave. |
||
| 337 | * @throws MongoCursorException |
||
| 338 | * @return MongoCursor Returns this cursor |
||
| 339 | */ |
||
| 340 | public function slaveOkay($okay = true) |
||
| 348 | |||
| 349 | /** |
||
| 350 | * Use snapshot mode for the query |
||
| 351 | * @link http://www.php.net/manual/en/mongocursor.snapshot.php |
||
| 352 | * @throws MongoCursorException |
||
| 353 | * @return MongoCursor Returns this cursor |
||
| 354 | */ |
||
| 355 | public function snapshot() |
||
| 362 | |||
| 363 | /** |
||
| 364 | * Sorts the results by given fields |
||
| 365 | * @link http://www.php.net/manual/en/mongocursor.sort.php |
||
| 366 | * @param array $fields An array of fields by which to sort. Each element in the array has as key the field name, and as value either 1 for ascending sort, or -1 for descending sort |
||
| 367 | * @throws MongoCursorException |
||
| 368 | * @return MongoCursor Returns the same cursor that this method was called on |
||
| 369 | */ |
||
| 370 | public function sort(array $fields) |
||
| 377 | |||
| 378 | /** |
||
| 379 | * Sets whether this cursor will be left open after fetching the last results |
||
| 380 | * @link http://www.php.net/manual/en/mongocursor.tailable.php |
||
| 381 | * @param bool $tail If the cursor should be tailable. |
||
| 382 | * @return MongoCursor Returns this cursor |
||
| 383 | */ |
||
| 384 | public function tailable($tail = true) |
||
| 391 | |||
| 392 | /** |
||
| 393 | * @return int|null |
||
| 394 | */ |
||
| 395 | protected function convertCursorType() |
||
| 403 | |||
| 404 | protected function convertModifiers() |
||
| 418 | |||
| 419 | /** |
||
| 420 | * @return Cursor |
||
| 421 | */ |
||
| 422 | protected function ensureCursor() |
||
| 430 | |||
| 431 | /** |
||
| 432 | * @return array |
||
| 433 | */ |
||
| 434 | protected function getCursorInfo() |
||
| 446 | } |
||
| 447 |
You can fix this by adding a namespace to your class:
When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.