-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMongoCursorPlus.class.php
48 lines (43 loc) · 1.22 KB
/
MongoCursorPlus.class.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
<?php
/**
* Provides tighter integration for lists of mongocollectionplus objects. This is returned by mongocollectionplus instead of a standard cursor if you call findObjects
* @author Micah Stevens <[email protected]>
* @version 1.0 - initial release
*
* @package MongoPlusPHP
*/
class MongoCursorPlus extends MongoCursor
{
var $db; // db object
var $collectionType;
function __construct($db, $className, $collectionName, $query)
{
$this->db = $db;
$this->collectionType = $className;
parent::__construct( $this->db, $collectionName, $query, array());
}
/**
* grabs the array from the parent, and creates an object that matches the passed collection and returns it populated with the data.
*
* @return object instance of the populated collection object
*/
function current()
{
$current = parent::current();
if ($current === null)
{
return null; // nothing is nothing
}
// if it's a temp collection, we need to pass the generated name over.
if ($this->collectionType == 'MongoTempCollection')
{
$object = new $this->collectionType($this->db, $collectionName);
}
else
{
$object = new $this->collectionType($this->db);
}
$object->loadRow($current);
return $object;
}
}