예제 #1
0
 public final function limit($limit = NULL)
 {
     if (TRUE === is_null($limit)) {
         return $this->limit;
     }
     Kit::ensureInt($limit);
     $this->limit = $limit;
     return $this;
 }
예제 #2
0
 /**
  * Queries this collection, returning an array or a MongoDBCursor for the result set.
  * @param array   $criterion  Associative array with fields to match.
  * @param array   $projection Fields of the results to return. The _id field is always returned.
  * @param array   $sort_by    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.
  *                            Each result is first sorted on the first field in the array,
  *                            then (if it exists) on the second field in the array, etc.
  *                            This means that the order of the fields in the fields array
  *                            is important.
  * @param int     $skip       The number of matching documents to skip before returning results.
  * @param int     $limit      The maximum number of matching documents to return.
  * @param boolean $to_array   Whether it should return an array instead of a MongoDBCursor.
  * @return array|MongoDBCursor Returns an array or a cursor for the results
  *                             matching the criterion.
  */
 private final function mongoFind($criterion = [], $projection = [], $sort_by = NULL, $skip = NULL, $limit = NULL, $to_array = FALSE)
 {
     $this->ensureInitialized();
     // Kit::ensureDict($criterion); // @CAUTION
     Kit::ensureArray($criterion);
     // Kit::ensureDict($projection); // @CAUTION
     Kit::ensureArray($projection);
     // Kit::ensureDict($sort_by, TRUE); // @CAUTION
     Kit::ensureArray($sort_by, TRUE);
     Kit::ensureInt($skip, TRUE);
     Kit::ensureInt($limit, TRUE);
     Kit::ensureBoolean($to_array);
     $cursor = $this->collection->find($criterion, $projection);
     if (FALSE === is_null($sort_by)) {
         $cursor = $cursor->sort($sort_by);
     }
     if (FALSE === is_null($skip)) {
         $cursor = $cursor->skip($skip);
     }
     if (FALSE === is_null($limit)) {
         $cursor = $cursor->limit($limit);
     }
     if (TRUE === $to_array) {
         return iterator_to_array($cursor, FALSE);
     } else {
         return new MongoDBCursor($cursor);
     }
 }
예제 #3
0
 public static final function daysAfterNow($days)
 {
     Kit::ensureInt($days);
     return new MongoDate((new DateTime())->add(new DateInterval("P{$days}D"))->getTimestamp());
 }