PHP Class Mongolid\Cursor\Cursor

By doing this we can, call 'sort', 'skip', 'limit' and others after calling 'where'. Because the mongodb library's MongoDB\Cursor is much more limited (in that regard) than the old driver MongoCursor.
Inheritance: implements Mongolid\Cursor\CursorInterface, implements Serializabl\Serializable
Show file Open project: leroy-merlin-br/mongolid Class Usage Examples

Public Properties

Property Type Description
$entitySchema string Schema that describes the entity that will be retrieved when iterating through the cursor.

Protected Properties

Property Type Description
$assembler Mongolid\DataMapper\EntityAssembler Have the responsibility of assembling the data coming from the database into actual entities.
$collection MongoDB\Collection
$command string The command that is being called in the $collection.
$converter Mongolid\Serializer\Type\Converter Object responsible to convert domain objects to mongo objects and vice versa.
$cursor MongoDB\Driver\Cursor The MongoDB cursor used to interact with db.
$params array The parameters of the $command.
$position integer Iterator position (to be used with foreach).

Public Methods

Method Description
__construct ( Schema $entitySchema, MongoDB\Collection $collection, string $command, array $params )
all ( ) : array Convert the cursor instance to an array of Objects.
count ( ) : integer Counts the number of results for this cursor.
current ( ) : mixed Iterator interface current. Return a model object with cursor document. (used in foreach).
disableTimeout ( boolean $flag = true ) : Cursor Disable idle timeout of 10 minutes from MongoDB cursor.
first ( ) : mixed Returns the first element of the cursor.
fresh ( ) : void Refresh the cursor in order to be able to perform a rewind and iterate through it again. A new request to the database will be made in the next iteration.
key ( ) : integer Iterator key method (used in foreach).
limit ( integer $amount ) : Cursor Limits the number of results returned.
next ( ) : void Iterator next method (used in foreach).
rewind ( ) : void Iterator interface rewind (used in foreach).
serialize ( ) : string Serializes this object storing the collection name instead of the actual MongoDb\Collection (which is unserializable).
skip ( integer $amount ) : Cursor Skips a number of results.
sort ( array $fields ) : Cursor Sorts the results by given fields.
toArray ( ) : array Convert the cursor instance to a full associative array.
unserialize ( mixed $serialized ) : void Unserializes this object. Re-creating the database connection.
valid ( ) : boolean Iterator valid method (used in foreach).

Protected Methods

Method Description
getAssembler ( ) : EntityAssembler Retrieves an EntityAssembler instance.
getConverter ( ) : Converter Converter is responsible to convert domain objects to mongo objects and vice versa.
getCursor ( ) : Traversable Actually returns a Traversable object with the DriverCursor within.

Method Details

__construct() public method

public __construct ( Schema $entitySchema, MongoDB\Collection $collection, string $command, array $params )
$entitySchema Mongolid\Schema\Schema Schema that describes the entity that will be retrieved from the database.
$collection MongoDB\Collection The raw collection object that will be used to retrieve the documents.
$command string The command that is being called in the $collection.
$params array The parameters of the $command.

all() public method

Convert the cursor instance to an array of Objects.
public all ( ) : array
return array

count() public method

Counts the number of results for this cursor.
public count ( ) : integer
return integer The number of documents returned by this cursor's query.

current() public method

Iterator interface current. Return a model object with cursor document. (used in foreach).
public current ( ) : mixed
return mixed

disableTimeout() public method

This method should be called before the cursor was started.
public disableTimeout ( boolean $flag = true ) : Cursor
$flag boolean Toggle timeout on or off.
return Cursor Returns this cursor.

first() public method

Returns the first element of the cursor.
public first ( ) : mixed
return mixed

fresh() public method

Refresh the cursor in order to be able to perform a rewind and iterate through it again. A new request to the database will be made in the next iteration.
public fresh ( ) : void
return void

getAssembler() protected method

Retrieves an EntityAssembler instance.
protected getAssembler ( ) : EntityAssembler
return Mongolid\DataMapper\EntityAssembler

getConverter() protected method

Converter is responsible to convert domain objects to mongo objects and vice versa.
protected getConverter ( ) : Converter
return Mongolid\Serializer\Type\Converter

getCursor() protected method

If it does not exists yet, create it using the $collection, $command and $params given.
protected getCursor ( ) : Traversable
return Traversable

key() public method

Iterator key method (used in foreach).
public key ( ) : integer
return integer

limit() public method

Limits the number of results returned.
public limit ( integer $amount ) : Cursor
$amount integer The number of results to return.
return Cursor Returns this cursor.

next() public method

Iterator next method (used in foreach).
public next ( ) : void
return void

rewind() public method

Iterator interface rewind (used in foreach).
public rewind ( ) : void
return void

serialize() public method

Serializes this object storing the collection name instead of the actual MongoDb\Collection (which is unserializable).
public serialize ( ) : string
return string Serialized object.

skip() public method

Skips a number of results.
public skip ( integer $amount ) : Cursor
$amount integer The number of results to skip.
return Cursor Returns this cursor.

sort() public method

Sorts the results by given fields.
public sort ( array $fields ) : Cursor
$fields array An array of fields by which to sort. Each element in the array has as key the field name, and as value either 1 for ascending sort, or -1 for descending sort.
return Cursor Returns this cursor.

toArray() public method

Convert the cursor instance to a full associative array.
public toArray ( ) : array
return array

unserialize() public method

Unserializes this object. Re-creating the database connection.
public unserialize ( mixed $serialized ) : void
$serialized mixed Serialized cursor.
return void

valid() public method

Iterator valid method (used in foreach).
public valid ( ) : boolean
return boolean

Property Details

$assembler protected property

Have the responsibility of assembling the data coming from the database into actual entities.
protected EntityAssembler,Mongolid\DataMapper $assembler
return Mongolid\DataMapper\EntityAssembler

$collection protected property

protected Collection,MongoDB $collection
return MongoDB\Collection

$command protected property

The command that is being called in the $collection.
protected string $command
return string

$converter protected property

Object responsible to convert domain objects to mongo objects and vice versa.
protected Converter,Mongolid\Serializer\Type $converter
return Mongolid\Serializer\Type\Converter

$cursor protected property

The MongoDB cursor used to interact with db.
protected Cursor,MongoDB\Driver $cursor
return MongoDB\Driver\Cursor

$entitySchema public property

Schema that describes the entity that will be retrieved when iterating through the cursor.
public string $entitySchema
return string

$params protected property

The parameters of the $command.
protected array $params
return array

$position protected property

Iterator position (to be used with foreach).
protected int $position
return integer