MongoGridFSCursor.php 2.4 KB

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