class Cursor implements CursorInterface (View source)

Wrapper for the Doctrine\MongoDB\Cursor class.

This class composes a Doctrine\MongoDB\Cursor instance and wraps its methods in order to return results as hydrated document class instances. Hydration behavior may be controlled with the {@link Cursor::hydrate()} method.

For compatibility, this class also extends Doctrine\MongoDB\Cursor.

Methods

__construct(CursorInterface $baseCursor, UnitOfWork $unitOfWork, ClassMetadata $class)

Constructor.

CursorInterface
getBaseCursor()

Return the wrapped Doctrine\MongoDB\Cursor instance.

Connection
getConnection()

Return the database connection for this cursor.

Collection
getCollection()

Return the collection for this cursor.

array
getFields()

Return the selected fields (projection).

array
getHints()

Get hints for UnitOfWork behavior.

setHints(array $hints)

Set hints for UnitOfWork behavior.

array
getQuery()

Return the query criteria.

$this
addOption(string $key, mixed $value)

Wrapper method for MongoCursor::addOption().

$this
batchSize(integer $num)

Wrapper method for MongoCursor::batchSize().

integer
count(boolean $foundOnly = false)

Wrapper method for MongoCursor::count().

array|object|null
current()

Wrapper method for MongoCursor::current().

boolean
dead()

Wrapper method for MongoCursor::dead().

array
explain()

Wrapper method for MongoCursor::explain().

$this
fields(array $f)

Wrapper method for MongoCursor::fields().

array|object|null
getNext()

Wrapper method for MongoCursor::getNext().

array
getReadPreference()

Wrapper method for MongoCursor::getReadPreference().

$this
setReadPreference(string $readPreference, array $tags = null)

Wrapper method for MongoCursor::setReadPreference().

array|object|null
getSingleResult()

Reset the cursor and return its first result.

getUseIdentifierKeys()

{@inheritDoc}

setUseIdentifierKeys($useIdentifierKeys)

{@inheritDoc}

hasNext()

{@inheritDoc}

$this
hint(array|string $keyPattern)

Wrapper method for MongoCursor::hint().

$this
hydrate(boolean $hydrate = true)

Set whether to hydrate results as document class instances.

$this
immortal(boolean $liveForever = true)

Wrapper method for MongoCursor::immortal().

array
info()

Wrapper method for MongoCursor::info().

string
key()

Wrapper method for MongoCursor::key().

$this
limit(integer $num)

Wrapper method for MongoCursor::limit().

next()

Wrapper method for MongoCursor::next().

recreate()

Recreates the internal MongoCursor.

$this
refresh(boolean $refresh = true)

Set whether to refresh hydrated documents that are already in the identity map.

reset()

Wrapper method for MongoCursor::reset().

rewind()

Wrapper method for MongoCursor::rewind().

$this
skip(integer $num)

Wrapper method for MongoCursor::skip().

$this
slaveOkay(boolean $ok = true)

Wrapper method for MongoCursor::slaveOkay().

$this
snapshot()

Wrapper method for MongoCursor::snapshot().

$this
sort(array $fields)

Wrapper method for MongoCursor::sort().

$this
tailable(boolean $tail = true)

Wrapper method for MongoCursor::tailable().

$this
timeout(integer $ms)

Wrapper method for MongoCursor::timeout().

array
toArray(boolean $useIdentifierKeys = null)

Return the cursor's results as an array.

boolean
valid()

Wrapper method for MongoCursor::valid().

$this
enableReferencePriming(array $primers, ReferencePrimer $referencePrimer)

No description

primeReferences()

Prime references

primeReferencesForSingleResult(object $document)

Primes all references for a single document only. This avoids iterating over the entire cursor when getSingleResult() is called.

Details

__construct(CursorInterface $baseCursor, UnitOfWork $unitOfWork, ClassMetadata $class)

Constructor.

Parameters

CursorInterface $baseCursor Cursor instance being wrapped
UnitOfWork $unitOfWork UnitOfWork for result hydration and query preparation
ClassMetadata $class ClassMetadata for the document class being queried

CursorInterface getBaseCursor()

Return the wrapped Doctrine\MongoDB\Cursor instance.

Return Value

CursorInterface

Connection getConnection()

Return the database connection for this cursor.

Return Value

Connection

See also

\Doctrine\MongoDB\Cursor::getConnection()

Collection getCollection()

Return the collection for this cursor.

Return Value

Collection

See also

CursorInterface::getCollection()

array getFields()

Return the selected fields (projection).

Return Value

array

See also

CursorInterface::getFields()

array getHints()

Get hints for UnitOfWork behavior.

Return Value

array

setHints(array $hints)

Set hints for UnitOfWork behavior.

Parameters

array $hints

array getQuery()

Return the query criteria.

Return Value

array

See also

CursorInterface::getQuery()

$this addOption(string $key, mixed $value)

Wrapper method for MongoCursor::addOption().

Parameters

string $key
mixed $value

Return Value

$this

See also

CursorInterface::addOption()
http://php.net/manual/en/mongocursor.addoption.php

$this batchSize(integer $num)

Wrapper method for MongoCursor::batchSize().

Parameters

integer $num

Return Value

$this

See also

CursorInterface::batchSize()
http://php.net/manual/en/mongocursor.batchsize.php

integer count(boolean $foundOnly = false)

Wrapper method for MongoCursor::count().

Parameters

boolean $foundOnly

Return Value

integer

See also

CursorInterface::count()
http://php.net/manual/en/countable.count.php
http://php.net/manual/en/mongocursor.count.php

array|object|null current()

Wrapper method for MongoCursor::current().

If configured, the result may be a hydrated document class instance.

Return Value

array|object|null

See also

CursorInterface::current()
http://php.net/manual/en/iterator.current.php
http://php.net/manual/en/mongocursor.current.php

boolean dead()

Wrapper method for MongoCursor::dead().

Return Value

boolean

See also

CursorInterface::dead()
http://php.net/manual/en/mongocursor.dead.php

array explain()

Wrapper method for MongoCursor::explain().

Return Value

array

See also

CursorInterface::explain()
http://php.net/manual/en/mongocursor.explain.php

$this fields(array $f)

Wrapper method for MongoCursor::fields().

Parameters

array $f Fields to return (or not return).

Return Value

$this

See also

CursorInterface::fields()
http://php.net/manual/en/mongocursor.fields.php

array|object|null getNext()

Wrapper method for MongoCursor::getNext().

If configured, the result may be a hydrated document class instance.

Return Value

array|object|null

See also

CursorInterface::getNext()
http://php.net/manual/en/mongocursor.getnext.php

array getReadPreference()

Wrapper method for MongoCursor::getReadPreference().

Return Value

array

See also

CursorInterface::getReadPreference()
http://php.net/manual/en/mongocursor.getreadpreference.php

$this setReadPreference(string $readPreference, array $tags = null)

Wrapper method for MongoCursor::setReadPreference().

Parameters

string $readPreference
array $tags

Return Value

$this

See also

CursorInterface::setReadPreference()
http://php.net/manual/en/mongocursor.setreadpreference.php

array|object|null getSingleResult()

Reset the cursor and return its first result.

The cursor will be reset both before and after the single result is fetched. The original cursor limit (if any) will remain in place.

Return Value

array|object|null

See also

Iterator::getSingleResult()

getUseIdentifierKeys()

{@inheritDoc}

setUseIdentifierKeys($useIdentifierKeys)

{@inheritDoc}

Parameters

$useIdentifierKeys

hasNext()

{@inheritDoc}

$this hint(array|string $keyPattern)

Wrapper method for MongoCursor::hint().

This method is intended for setting MongoDB query hints, which are unrelated to UnitOfWork hints.

Parameters

array|string $keyPattern

Return Value

$this

See also

CursorInterface::hint()
http://php.net/manual/en/mongocursor.hint.php

$this hydrate(boolean $hydrate = true)

Set whether to hydrate results as document class instances.

Parameters

boolean $hydrate

Return Value

$this

$this immortal(boolean $liveForever = true)

Wrapper method for MongoCursor::immortal().

Parameters

boolean $liveForever

Return Value

$this

See also

CursorInterface::immortal()
http://php.net/manual/en/mongocursor.immortal.php

array info()

Wrapper method for MongoCursor::info().

Return Value

array

See also

CursorInterface::info()
http://php.net/manual/en/mongocursor.info.php

string key()

Wrapper method for MongoCursor::key().

$this limit(integer $num)

Wrapper method for MongoCursor::limit().

Parameters

integer $num

Return Value

$this

See also

CursorInterface::limit()
http://php.net/manual/en/mongocursor.limit.php

next()

Wrapper method for MongoCursor::next().

recreate()

Recreates the internal MongoCursor.

See also

CursorInterface::recreate()

$this refresh(boolean $refresh = true)

Set whether to refresh hydrated documents that are already in the identity map.

This option has no effect if hydration is disabled.

Parameters

boolean $refresh

Return Value

$this

reset()

Wrapper method for MongoCursor::reset().

rewind()

Wrapper method for MongoCursor::rewind().

$this skip(integer $num)

Wrapper method for MongoCursor::skip().

Parameters

integer $num

Return Value

$this

See also

CursorInterface::skip()
http://php.net/manual/en/mongocursor.skip.php

$this slaveOkay(boolean $ok = true)

Wrapper method for MongoCursor::slaveOkay().

Parameters

boolean $ok

Return Value

$this

See also

CursorInterface::slaveOkay()
http://php.net/manual/en/mongocursor.slaveokay.php

$this snapshot()

Wrapper method for MongoCursor::snapshot().

Return Value

$this

See also

CursorInterface::snapshot()
http://php.net/manual/en/mongocursor.snapshot.php

$this sort(array $fields)

Wrapper method for MongoCursor::sort().

Field names will be prepared according to the document mapping.

Parameters

array $fields

Return Value

$this

See also

CursorInterface::sort()
http://php.net/manual/en/mongocursor.sort.php

$this tailable(boolean $tail = true)

Wrapper method for MongoCursor::tailable().

Parameters

boolean $tail

Return Value

$this

See also

CursorInterface::tailable()
http://php.net/manual/en/mongocursor.tailable.php

$this timeout(integer $ms)

Wrapper method for MongoCursor::timeout().

Parameters

integer $ms

Return Value

$this

See also

CursorInterface::timeout()
http://php.net/manual/en/mongocursor.timeout.php

array toArray(boolean $useIdentifierKeys = null)

Return the cursor's results as an array.

If documents in the result set use BSON objects for their "_id", the $useKeys parameter may be set to false to avoid errors attempting to cast arrays (i.e. BSON objects) to string keys.

Parameters

boolean $useIdentifierKeys

Return Value

array

See also

Iterator::toArray()

boolean valid()

Wrapper method for MongoCursor::valid().

$this enableReferencePriming(array $primers, ReferencePrimer $referencePrimer)

Parameters

array $primers
ReferencePrimer $referencePrimer

Return Value

$this

protected primeReferences()

Prime references

protected primeReferencesForSingleResult(object $document)

Primes all references for a single document only. This avoids iterating over the entire cursor when getSingleResult() is called.

Parameters

object $document