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