| 1 | <?php |
||
| 25 | class MongoCursor extends AbstractCursor implements Iterator |
||
|
1 ignored issue
–
show
|
|||
| 26 | { |
||
| 27 | /** |
||
| 28 | * @var bool |
||
| 29 | */ |
||
| 30 | public static $slaveOkay = false; |
||
| 31 | |||
| 32 | /** |
||
| 33 | * @var int |
||
| 34 | */ |
||
| 35 | public static $timeout = 30000; |
||
| 36 | |||
| 37 | /** |
||
| 38 | * @var array |
||
| 39 | */ |
||
| 40 | protected $optionNames = [ |
||
| 41 | 'allowPartialResults', |
||
| 42 | 'batchSize', |
||
| 43 | 'cursorType', |
||
| 44 | 'limit', |
||
| 45 | 'maxTimeMS', |
||
| 46 | 'modifiers', |
||
| 47 | 'noCursorTimeout', |
||
| 48 | 'projection', |
||
| 49 | 'readPreference', |
||
| 50 | 'skip', |
||
| 51 | 'sort', |
||
| 52 | ]; |
||
| 53 | |||
| 54 | /** |
||
| 55 | * @var array |
||
| 56 | */ |
||
| 57 | protected $projection; |
||
| 58 | |||
| 59 | /** |
||
| 60 | * @var array |
||
| 61 | */ |
||
| 62 | protected $query; |
||
| 63 | |||
| 64 | protected $allowPartialResults; |
||
| 65 | protected $awaitData; |
||
| 66 | protected $flags = 0; |
||
| 67 | protected $hint; |
||
| 68 | protected $limit; |
||
| 69 | protected $maxTimeMS; |
||
| 70 | protected $noCursorTimeout; |
||
| 71 | protected $options = []; |
||
| 72 | protected $skip; |
||
| 73 | protected $snapshot; |
||
| 74 | protected $sort; |
||
| 75 | protected $tailable; |
||
| 76 | |||
| 77 | /** |
||
| 78 | * Create a new cursor |
||
| 79 | * @link http://www.php.net/manual/en/mongocursor.construct.php |
||
| 80 | * @param MongoClient $connection Database connection. |
||
| 81 | * @param string $ns Full name of database and collection. |
||
| 82 | * @param array $query Database query. |
||
| 83 | * @param array $fields Fields to return. |
||
| 84 | */ |
||
| 85 | public function __construct(MongoClient $connection, $ns, array $query = array(), array $fields = array()) |
||
| 92 | |||
| 93 | /** |
||
| 94 | * Adds a top-level key/value pair to a query |
||
| 95 | * @link http://www.php.net/manual/en/mongocursor.addoption.php |
||
| 96 | * @param string $key Fieldname to add. |
||
| 97 | * @param mixed $value Value to add. |
||
| 98 | * @throws MongoCursorException |
||
| 99 | * @return MongoCursor Returns this cursor |
||
| 100 | */ |
||
| 101 | public function addOption($key, $value) |
||
| 108 | |||
| 109 | /** |
||
| 110 | * (PECL mongo >= 1.2.11)<br/> |
||
| 111 | * Sets whether this cursor will wait for a while for a tailable cursor to return more data |
||
| 112 | * @param bool $wait [optional] <p>If the cursor should wait for more data to become available.</p> |
||
| 113 | * @return MongoCursor Returns this cursor. |
||
| 114 | */ |
||
| 115 | public function awaitData($wait = true) |
||
| 122 | |||
| 123 | |||
| 124 | /** |
||
| 125 | * Counts the number of results for this query |
||
| 126 | * @link http://www.php.net/manual/en/mongocursor.count.php |
||
| 127 | * @param bool $foundOnly Send cursor limit and skip information to the count function, if applicable. |
||
| 128 | * @return int The number of documents returned by this cursor's query. |
||
| 129 | */ |
||
| 130 | public function count($foundOnly = false) |
||
| 131 | { |
||
| 132 | if ($foundOnly && $this->cursor !== null) { |
||
| 133 | return iterator_count($this->ensureIterator()); |
||
| 134 | } |
||
| 135 | |||
| 136 | $optionNames = ['hint', 'maxTimeMS']; |
||
| 137 | if ($foundOnly) { |
||
| 138 | $optionNames = array_merge($optionNames, ['limit', 'skip']); |
||
| 139 | } |
||
| 140 | |||
| 141 | $options = $this->getOptions($optionNames) + $this->options; |
||
| 142 | |||
| 143 | $count = $this->collection->count($this->query, $options); |
||
| 144 | return $count; |
||
| 145 | } |
||
| 146 | |||
| 147 | /** |
||
| 148 | * Execute the query |
||
| 149 | * @link http://www.php.net/manual/en/mongocursor.doquery.php |
||
| 150 | * @throws MongoConnectionException if it cannot reach the database. |
||
| 151 | * @return void |
||
| 152 | */ |
||
| 153 | protected function doQuery() |
||
| 159 | |||
| 160 | /** |
||
| 161 | * Return an explanation of the query, often useful for optimization and debugging |
||
| 162 | * @link http://www.php.net/manual/en/mongocursor.explain.php |
||
| 163 | * @return array Returns an explanation of the query. |
||
| 164 | */ |
||
| 165 | public function explain() |
||
| 169 | |||
| 170 | /** |
||
| 171 | * Sets the fields for a query |
||
| 172 | * @link http://www.php.net/manual/en/mongocursor.fields.php |
||
| 173 | * @param array $f Fields to return (or not return). |
||
| 174 | * @throws MongoCursorException |
||
| 175 | * @return MongoCursor |
||
| 176 | */ |
||
| 177 | public function fields(array $f) |
||
| 184 | |||
| 185 | /** |
||
| 186 | * Return the next object to which this cursor points, and advance the cursor |
||
| 187 | * @link http://www.php.net/manual/en/mongocursor.getnext.php |
||
| 188 | * @throws MongoConnectionException |
||
| 189 | * @throws MongoCursorTimeoutException |
||
| 190 | * @return array Returns the next object |
||
| 191 | */ |
||
| 192 | public function getNext() |
||
| 198 | |||
| 199 | /** |
||
| 200 | * Checks if there are any more elements in this cursor |
||
| 201 | * @link http://www.php.net/manual/en/mongocursor.hasnext.php |
||
| 202 | * @throws MongoConnectionException |
||
| 203 | * @throws MongoCursorTimeoutException |
||
| 204 | * @return bool Returns true if there is another element |
||
| 205 | */ |
||
| 206 | public function hasNext() |
||
| 211 | |||
| 212 | /** |
||
| 213 | * Gives the database a hint about the query |
||
| 214 | * @link http://www.php.net/manual/en/mongocursor.hint.php |
||
| 215 | * @param array|string $keyPattern Indexes to use for the query. |
||
| 216 | * @throws MongoCursorException |
||
| 217 | * @return MongoCursor Returns this cursor |
||
| 218 | */ |
||
| 219 | public function hint($keyPattern) |
||
| 226 | |||
| 227 | /** |
||
| 228 | * Sets whether this cursor will timeout |
||
| 229 | * @link http://www.php.net/manual/en/mongocursor.immortal.php |
||
| 230 | * @param bool $liveForever If the cursor should be immortal. |
||
| 231 | * @throws MongoCursorException |
||
| 232 | * @return MongoCursor Returns this cursor |
||
| 233 | */ |
||
| 234 | public function immortal($liveForever = true) |
||
| 241 | |||
| 242 | /** |
||
| 243 | * Limits the number of results returned |
||
| 244 | * @link http://www.php.net/manual/en/mongocursor.limit.php |
||
| 245 | * @param int $num The number of results to return. |
||
| 246 | * @throws MongoCursorException |
||
| 247 | * @return MongoCursor Returns this cursor |
||
| 248 | */ |
||
| 249 | public function limit($num) |
||
| 256 | |||
| 257 | /** |
||
| 258 | * @param int $ms |
||
| 259 | * @return $this |
||
| 260 | * @throws MongoCursorException |
||
| 261 | */ |
||
| 262 | public function maxTimeMS($ms) |
||
| 269 | |||
| 270 | /** |
||
| 271 | * @link http://www.php.net/manual/en/mongocursor.partial.php |
||
| 272 | * @param bool $okay [optional] <p>If receiving partial results is okay.</p> |
||
| 273 | * @return MongoCursor Returns this cursor. |
||
| 274 | */ |
||
| 275 | public function partial($okay = true) |
||
| 281 | |||
| 282 | /** |
||
| 283 | * Clears the cursor |
||
| 284 | * @link http://www.php.net/manual/en/mongocursor.reset.php |
||
| 285 | * @return void |
||
| 286 | */ |
||
| 287 | public function reset() |
||
| 291 | |||
| 292 | /** |
||
| 293 | * @link http://www.php.net/manual/en/mongocursor.setflag.php |
||
| 294 | * @param int $flag |
||
| 295 | * @param bool $set |
||
| 296 | * @return MongoCursor |
||
| 297 | */ |
||
| 298 | public function setFlag($flag, $set = true) |
||
| 302 | |||
| 303 | /** |
||
| 304 | * Skips a number of results |
||
| 305 | * @link http://www.php.net/manual/en/mongocursor.skip.php |
||
| 306 | * @param int $num The number of results to skip. |
||
| 307 | * @throws MongoCursorException |
||
| 308 | * @return MongoCursor Returns this cursor |
||
| 309 | */ |
||
| 310 | public function skip($num) |
||
| 317 | |||
| 318 | /** |
||
| 319 | * Sets whether this query can be done on a slave |
||
| 320 | * This method will override the static class variable slaveOkay. |
||
| 321 | * @link http://www.php.net/manual/en/mongocursor.slaveOkay.php |
||
| 322 | * @param boolean $okay If it is okay to query the slave. |
||
| 323 | * @throws MongoCursorException |
||
| 324 | * @return MongoCursor Returns this cursor |
||
| 325 | */ |
||
| 326 | public function slaveOkay($okay = true) |
||
| 331 | |||
| 332 | /** |
||
| 333 | * Use snapshot mode for the query |
||
| 334 | * @link http://www.php.net/manual/en/mongocursor.snapshot.php |
||
| 335 | * @throws MongoCursorException |
||
| 336 | * @return MongoCursor Returns this cursor |
||
| 337 | */ |
||
| 338 | public function snapshot() |
||
| 345 | |||
| 346 | /** |
||
| 347 | * Sorts the results by given fields |
||
| 348 | * @link http://www.php.net/manual/en/mongocursor.sort.php |
||
| 349 | * @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 |
||
| 350 | * @throws MongoCursorException |
||
| 351 | * @return MongoCursor Returns the same cursor that this method was called on |
||
| 352 | */ |
||
| 353 | public function sort(array $fields) |
||
| 360 | |||
| 361 | /** |
||
| 362 | * Sets whether this cursor will be left open after fetching the last results |
||
| 363 | * @link http://www.php.net/manual/en/mongocursor.tailable.php |
||
| 364 | * @param bool $tail If the cursor should be tailable. |
||
| 365 | * @return MongoCursor Returns this cursor |
||
| 366 | */ |
||
| 367 | public function tailable($tail = true) |
||
| 374 | |||
| 375 | /** |
||
| 376 | * @return int|null |
||
| 377 | */ |
||
| 378 | protected function convertCursorType() |
||
| 386 | |||
| 387 | protected function convertModifiers() |
||
| 401 | |||
| 402 | /** |
||
| 403 | * {@inheritdoc} |
||
| 404 | */ |
||
| 405 | protected function convertReadPreference() |
||
| 414 | |||
| 415 | /** |
||
| 416 | * @return Cursor |
||
| 417 | */ |
||
| 418 | protected function ensureCursor() |
||
| 426 | |||
| 427 | /** |
||
| 428 | * @return array |
||
| 429 | */ |
||
| 430 | protected function getCursorInfo() |
||
| 442 | } |
||
| 443 |
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.