MongoGridFSCursor.php 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  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. class MongoGridFSCursor extends MongoCursor implements Traversable, Iterator
  16. {
  17. /**
  18. * @static
  19. * @var $slaveOkay
  20. */
  21. public static $slaveOkay;
  22. /**
  23. * @link http://php.net/manual/en/class.mongogridfscursor.php#mongogridfscursor.props.gridfs
  24. * @var $gridfs
  25. */
  26. protected $gridfs;
  27. /**
  28. * Create a new cursor
  29. * @link http://php.net/manual/en/mongogridfscursor.construct.php
  30. * @param MongoGridFS $gridfs Related GridFS collection
  31. * @param resource $connection Database connection
  32. * @param string $ns Full name of database and collection
  33. * @param array $query Database query
  34. * @param array $fields Fields to return
  35. * @return MongoGridFSCursor Returns the new cursor
  36. */
  37. public function __construct(MongoGridFS $gridfs, $connection, $ns, array $query = array(), array $fields = array())
  38. {
  39. $this->gridfs = $gridfs;
  40. parent::__construct($connection, $ns, $query, $fields);
  41. }
  42. /**
  43. * Return the next file to which this cursor points, and advance the cursor
  44. * @link http://php.net/manual/en/mongogridfscursor.getnext.php
  45. * @return MongoGridFSFile Returns the next file
  46. */
  47. public function getNext()
  48. {
  49. $file = parent::next();
  50. return new MongoGridFSFile($this->gridfs, $file);
  51. }
  52. /**
  53. * Returns the current file
  54. * @link http://php.net/manual/en/mongogridfscursor.current.php
  55. * @return MongoGridFSFile The current file
  56. */
  57. public function current()
  58. {
  59. $file = parent::current();
  60. return new MongoGridFSFile($this->gridfs, $file);
  61. }
  62. /**
  63. * Returns the current result's filename
  64. * @link http://php.net/manual/en/mongogridfscursor.key.php
  65. * @return string The current results filename
  66. */
  67. public function key()
  68. {
  69. $file = parent::current();
  70. return isset($file['filename']) ? $file['filename'] : null;
  71. }
  72. }