-
Type: New Feature
-
Resolution: Duplicate
-
Priority: Minor - P4
-
None
-
Affects Version/s: None
-
Component/s: None
-
None
-
Environment:n/a
Copied from my post on the dev mailing list:
Would it be possible to add an option to a MongoCollection to allow
for the ability to pass in the class name of a class that extends
MongoCursor, so that it gets returned instead of the base MongoCursor?
I'd like to extend MongoCursor to override a couple of methods and add
some minor functionality. As it stands now, I have to create a wrapper
class and write one line methods to expose the individual MongoCursor
methods, like:
class ResultSet
{
/**
- @var MongoCursor
*/
protected $rs;
public function __construct( MongoCursor $rs ) { $this->rs = $rs; }public function current()
{ return $rs->current(); }public function valid()
{ return $this->rs->valid(); }public function key()
{ return $this->rs->key(); }}
Although this works, it would be much better for extensibility (not to
mention much cleaner) to be able to extend MongoCursor directly and
have MongoCollection return the new class instead. The other option
that I was just looking at is having a method in the MongoCursor class
that would take a MongoCursor and basically clone it into the current
object, but I'm not familiar with the underpinnings and how the C++
code works with the driver and at first glance that seems more
complicated.
An example of how this would look on the PHP side:
class ResultSet extends MongoCursor
{
public function current()
}
An option for specifying it could be:
$db = new Mongo( $server, array( 'custom_cursor' => 'ResultSet' ) );