MongoCursor.php 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326
  1. <?php
  2. /*
  3. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  4. * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  5. * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  6. * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  7. * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  8. * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  9. * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  10. * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  11. * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  12. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  13. * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  14. */
  15. /**
  16. * Result object for database query.
  17. * @link http://www.php.net/manual/en/class.mongocursor.php
  18. */
  19. class MongoCursor implements Iterator, Traversable {
  20. /**
  21. * @link http://php.net/manual/en/class.mongocursor.php#mongocursor.props.slaveokay
  22. * @static
  23. * @var bool $slaveOkay
  24. */
  25. public static $slaveOkay = FALSE;
  26. /**
  27. * @var int <p>
  28. * Set timeout in milliseconds for all database responses. Use
  29. * <em>-1</em> to wait forever. Can be overridden with
  30. * {link http://php.net/manual/en/mongocursor.timeout.php MongoCursor::timeout()}. This does not cause the
  31. * MongoDB server to cancel the operation; it only instructs the driver to
  32. * stop waiting for a response and throw a
  33. * {@link http://php.net/manual/en/class.mongocursortimeoutexception.php MongoCursorTimeoutException} after a set time.
  34. * </p>
  35. */
  36. static $timeout = 30000;
  37. /**
  38. * Create a new cursor
  39. * @link http://www.php.net/manual/en/mongocursor.construct.php
  40. * @param MongoClient $connection Database connection.
  41. * @param string $ns Full name of database and collection.
  42. * @param array $query Database query.
  43. * @param array $fields Fields to return.
  44. * @return MongoCursor Returns the new cursor
  45. */
  46. public function __construct($connection, $ns, array $query = array(), array $fields = array()) {}
  47. /**
  48. * (PECL mongo &gt;= 1.2.11)<br/>
  49. * Sets whether this cursor will wait for a while for a tailable cursor to return more data
  50. * @param bool $wait [optional] <p>If the cursor should wait for more data to become available.</p>
  51. * @return MongoCursor Returns this cursor.
  52. */
  53. public function awaitData ($wait = true) {}
  54. /**
  55. * Checks if there are any more elements in this cursor
  56. * @link http://www.php.net/manual/en/mongocursor.hasnext.php
  57. * @throws MongoConnectionException
  58. * @throws MongoCursorTimeoutException
  59. * @return bool Returns true if there is another element
  60. */
  61. public function hasNext() {}
  62. /**
  63. * Return the next object to which this cursor points, and advance the cursor
  64. * @link http://www.php.net/manual/en/mongocursor.getnext.php
  65. * @throws MongoConnectionException
  66. * @throws MongoCursorTimeoutException
  67. * @return array Returns the next object
  68. */
  69. public function getNext() {}
  70. /**
  71. * (PECL mongo &gt;= 1.3.3)<br/>
  72. * @link http://www.php.net/manual/en/mongocursor.getreadpreference.php
  73. * @return array This function returns an array describing the read preference. The array contains the values <em>type</em> for the string
  74. * read preference mode (corresponding to the {@link http://www.php.net/manual/en/class.mongoclient.php MongoClient} constants), and <em>tagsets</em> containing a list of all tag set criteria. If no tag sets were specified, <em>tagsets</em> will not be present in the array.
  75. */
  76. public function getReadPreference () { }
  77. /**
  78. * Limits the number of results returned
  79. * @link http://www.php.net/manual/en/mongocursor.limit.php
  80. * @param int $num The number of results to return.
  81. * @throws MongoCursorException
  82. * @return MongoCursor Returns this cursor
  83. */
  84. public function limit($num) {}
  85. /**
  86. * (PECL mongo &gt;= 1.2.0)<br/>
  87. * @link http://www.php.net/manual/en/mongocursor.partial.php
  88. * @param bool $okay [optional] <p>If receiving partial results is okay.</p>
  89. * @return MongoCursor Returns this cursor.
  90. */
  91. public function partial ($okay = true) {}
  92. /**
  93. * (PECL mongo &gt;= 1.2.1)<br/>
  94. * @link http://www.php.net/manual/en/mongocursor.setflag.php
  95. * @param int $flag <p>
  96. * Which flag to set. You can not set flag 6 (EXHAUST) as the driver does
  97. * not know how to handle them. You will get a warning if you try to use
  98. * this flag. For available flags, please refer to the wire protocol
  99. * {@link http://www.mongodb.org/display/DOCS/Mongo+Wire+Protocol#MongoWireProtocol-OPQUERY documentation}.
  100. * </p>
  101. * @param bool $set [optional] <p>Whether the flag should be set (<b>TRUE</b>) or unset (<b>FALSE</b>).</p>
  102. * @return MongoCursor
  103. */
  104. public function setFlag ($flag, $set = true ) {}
  105. /**
  106. * (PECL mongo &gt;= 1.3.3)<br/>
  107. * @link http://www.php.net/manual/en/mongocursor.setreadpreference.php
  108. * @param string $read_preference <p>The read preference mode: MongoClient::RP_PRIMARY, MongoClient::RP_PRIMARY_PREFERRED, MongoClient::RP_SECONDARY, MongoClient::RP_SECONDARY_PREFERRED, or MongoClient::RP_NEAREST.</p>
  109. * @param array $tags [optional] <p>The read preference mode: MongoClient::RP_PRIMARY, MongoClient::RP_PRIMARY_PREFERRED, MongoClient::RP_SECONDARY, MongoClient::RP_SECONDARY_PREFERRED, or MongoClient::RP_NEAREST.</p>
  110. * @return MongoCursor Returns this cursor.
  111. */
  112. public function setReadPreference ($read_preference, array $tags) {}
  113. /**
  114. * Skips a number of results
  115. * @link http://www.php.net/manual/en/mongocursor.skip.php
  116. * @param int $num The number of results to skip.
  117. * @throws MongoCursorException
  118. * @return MongoCursor Returns this cursor
  119. */
  120. public function skip($num) {}
  121. /**
  122. * Sets whether this query can be done on a slave
  123. * This method will override the static class variable slaveOkay.
  124. * @link http://www.php.net/manual/en/mongocursor.slaveOkay.php
  125. * @param boolean $okay If it is okay to query the slave.
  126. * @throws MongoCursorException
  127. * @return MongoCursor Returns this cursor
  128. */
  129. public function slaveOkay($okay = true) {}
  130. /**
  131. * Sets whether this cursor will be left open after fetching the last results
  132. * @link http://www.php.net/manual/en/mongocursor.tailable.php
  133. * @param bool $tail If the cursor should be tailable.
  134. * @return MongoCursor Returns this cursor
  135. */
  136. public function tailable($tail = true) {}
  137. /**
  138. * Sets whether this cursor will timeout
  139. * @link http://www.php.net/manual/en/mongocursor.immortal.php
  140. * @param bool $liveForever If the cursor should be immortal.
  141. * @throws MongoCursorException
  142. * @return MongoCursor Returns this cursor
  143. */
  144. public function immortal($liveForever = true) {}
  145. /**
  146. * Sets a client-side timeout for this query
  147. * @link http://www.php.net/manual/en/mongocursor.timeout.php
  148. * @param int $ms The number of milliseconds for the cursor to wait for a response. By default, the cursor will wait forever.
  149. * @throws MongoCursorTimeoutException
  150. * @return MongoCursor Returns this cursor
  151. */
  152. public function timeout($ms) {}
  153. /**
  154. * Checks if there are documents that have not been sent yet from the database for this cursor
  155. * @link http://www.php.net/manual/en/mongocursor.dead.php
  156. * @return boolean Returns if there are more results that have not been sent to the client, yet.
  157. */
  158. public function dead() {}
  159. /**
  160. * Use snapshot mode for the query
  161. * @link http://www.php.net/manual/en/mongocursor.snapshot.php
  162. * @throws MongoCursorException
  163. * @return MongoCursor Returns this cursor
  164. */
  165. public function snapshot() {}
  166. /**
  167. * Sorts the results by given fields
  168. * @link http://www.php.net/manual/en/mongocursor.sort.php
  169. * @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
  170. * @throws MongoCursorException
  171. * @return MongoCursor Returns the same cursor that this method was called on
  172. */
  173. public function sort(array $fields) {}
  174. /**
  175. * Gives the database a hint about the query
  176. * @link http://www.php.net/manual/en/mongocursor.hint.php
  177. * @param array $key_pattern Indexes to use for the query.
  178. * @throws MongoCursorException
  179. * @return MongoCursor Returns this cursor
  180. */
  181. public function hint(array $key_pattern) {}
  182. /**
  183. * Adds a top-level key/value pair to a query
  184. * @link http://www.php.net/manual/en/mongocursor.addoption.php
  185. * @param string $key Fieldname to add.
  186. * @param mixed $value Value to add.
  187. * @throws MongoCursorException
  188. * @return MongoCursor Returns this cursor
  189. */
  190. public function addOption($key, $value) {}
  191. /**
  192. * Execute the query
  193. * @link http://www.php.net/manual/en/mongocursor.doquery.php
  194. * @throws MongoConnectionException if it cannot reach the database.
  195. * @return void
  196. */
  197. protected function doQuery() {}
  198. /**
  199. * Returns the current element
  200. * @link http://www.php.net/manual/en/mongocursor.current.php
  201. * @return array
  202. */
  203. public function current() {}
  204. /**
  205. * Returns the current result's _id
  206. * @link http://www.php.net/manual/en/mongocursor.key.php
  207. * @return string The current result's _id as a string.
  208. */
  209. public function key() {}
  210. /**
  211. * Advances the cursor to the next result
  212. * @link http://www.php.net/manual/en/mongocursor.next.php
  213. * @throws MongoConnectionException
  214. * @throws MongoCursorTimeoutException
  215. * @return void
  216. */
  217. public function next() {}
  218. /**
  219. * Returns the cursor to the beginning of the result set
  220. * @throws MongoConnectionException
  221. * @throws MongoCursorTimeoutException
  222. * @return void
  223. */
  224. public function rewind() {}
  225. /**
  226. * Checks if the cursor is reading a valid result.
  227. * @link http://www.php.net/manual/en/mongocursor.valid.php
  228. * @return boolean If the current result is not null.
  229. */
  230. public function valid() {}
  231. /**
  232. * Clears the cursor
  233. * @link http://www.php.net/manual/en/mongocursor.reset.php
  234. * @return void
  235. */
  236. public function reset() {}
  237. /**
  238. * Return an explanation of the query, often useful for optimization and debugging
  239. * @link http://www.php.net/manual/en/mongocursor.explain.php
  240. * @return array Returns an explanation of the query.
  241. */
  242. public function explain() {}
  243. /**
  244. * Counts the number of results for this query
  245. * @link http://www.php.net/manual/en/mongocursor.count.php
  246. * @param bool $all Send cursor limit and skip information to the count function, if applicable.
  247. * @return int The number of documents returned by this cursor's query.
  248. */
  249. public function count($all = FALSE) {}
  250. /**
  251. * Sets the fields for a query
  252. * @link http://www.php.net/manual/en/mongocursor.fields.php
  253. * @param array $f Fields to return (or not return).
  254. * @throws MongoCursorException
  255. * @return MongoCursor
  256. */
  257. public function fields(array $f){}
  258. /**
  259. * Gets the query, fields, limit, and skip for this cursor
  260. * @link http://www.php.net/manual/en/mongocursor.info.php
  261. * @return array The query, fields, limit, and skip for this cursor as an associative array.
  262. */
  263. public function info(){}
  264. /**
  265. * PECL mongo >=1.0.11
  266. * Limits the number of elements returned in one batch.
  267. * <p>A cursor typically fetches a batch of result objects and store them locally.
  268. * This method sets the batchSize value to configure the amount of documents retrieved from the server in one data packet.
  269. * However, it will never return more documents than fit in the max batch size limit (usually 4MB).
  270. *
  271. * @param int $batchSize The number of results to return per batch. Each batch requires a round-trip to the server.
  272. * <p>If batchSize is 2 or more, it represents the size of each batch of objects retrieved.
  273. * It can be adjusted to optimize performance and limit data transfer.
  274. *
  275. * <p>If batchSize is 1 or negative, it will limit of number returned documents to the absolute value of batchSize,
  276. * and the cursor will be closed. For example if batchSize is -10, then the server will return a maximum of 10
  277. * documents and as many as can fit in 4MB, then close the cursor.
  278. * <b>Warning</b>
  279. * <p>A batchSize of 1 is special, and means the same as -1, i.e. a value of 1 makes the cursor only capable of returning one document.
  280. * <p>Note that this feature is different from MongoCursor::limit() in that documents must fit within a maximum size,
  281. * and it removes the need to send a request to close the cursor server-side.
  282. * The batch size can be changed even after a cursor is iterated, in which case the setting will apply on the next batch retrieval.
  283. * <p>This cannot override MongoDB's limit on the amount of data it will return to the client (i.e.,
  284. * if you set batch size to 1,000,000,000, MongoDB will still only return 4-16MB of results per batch).
  285. * <p>To ensure consistent behavior, the rules of MongoCursor::batchSize() and MongoCursor::limit() behave a little complex
  286. * but work "as expected". The rules are: hard limits override soft limits with preference given to MongoCursor::limit() over
  287. * MongoCursor::batchSize(). After that, whichever is set and lower than the other will take precedence.
  288. * See below. section for some examples.
  289. * @return MongoCursor Returns this cursor.
  290. * @link http://docs.php.net/manual/en/mongocursor.batchsize.php
  291. */
  292. public function batchSize($batchSize){}
  293. }