PHP Class Mongolid\Cursor\EmbeddedCursor

By doing this we can use '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
Show file Open project: leroy-merlin-br/mongolid

Public Properties

Property Type Description
$entityClass string Entity class that will be returned while iterating.

Protected Properties

Property Type Description
$items array The actual array of embedded documents.

Public Methods

Method Description
__construct ( string $entityClass, array $items )
all ( ) : array Convert the cursor instance to an array of Items.
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).
first ( ) : mixed Returns the first element of the cursor.
key ( ) : integer Iterator key method (used in foreach).
limit ( integer $amount ) : EmbeddedCursor Limits the number of results returned.
next ( ) : void Iterator next method (used in foreach).
rewind ( ) : void Iterator interface rewind (used in foreach).
skip ( integer $amount ) : EmbeddedCursor Skips a number of results.
sort ( array $fields ) : EmbeddedCursor Sorts the results by given fields.
toArray ( ) : array Return the raw cursor items.
valid ( ) : boolean Iterator valid method (used in foreach).

Protected Methods

Method Description
getSchemaForEntity ( ) : Schema Retrieve a schema based on Entity Class.

Method Details

__construct() public method

public __construct ( string $entityClass, array $items )
$entityClass string Class of the objects that will be retrieved by the cursor.
$items array The items array.

all() public method

Convert the cursor instance to an array of Items.
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

first() public method

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

getSchemaForEntity() protected method

Retrieve a schema based on Entity Class.
protected getSchemaForEntity ( ) : Schema
return Mongolid\Schema\Schema

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 ) : EmbeddedCursor
$amount integer The number of results to return.
return EmbeddedCursor 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

skip() public method

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

sort() public method

Sorts the results by given fields.
public sort ( array $fields ) : EmbeddedCursor
$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 EmbeddedCursor Returns this cursor.

toArray() public method

Return the raw cursor items.
public toArray ( ) : array
return array

valid() public method

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

Property Details

$entityClass public property

Entity class that will be returned while iterating.
public string $entityClass
return string

$items protected property

The actual array of embedded documents.
protected array $items
return array