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.

addOption(string $key, mixed $value)

Wrapper method for MongoCursor::addOption().

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().

fields(array $f)

Wrapper method for MongoCursor::fields().

array|object|null
getNext()

Wrapper method for MongoCursor::getNext().

array
getReadPreference()

Wrapper method for MongoCursor::getReadPreference().

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}

hint(array|string $keyPattern)

Wrapper method for MongoCursor::hint().

hydrate(boolean $hydrate = true)

Set whether to hydrate results as document class instances.

immortal(boolean $liveForever = true)

Wrapper method for MongoCursor::immortal().

array
info()

Wrapper method for MongoCursor::info().

string
key()

Wrapper method for MongoCursor::key().

limit(integer $num)

Wrapper method for MongoCursor::limit().

next()

Wrapper method for MongoCursor::next().

recreate()

Recreates the internal MongoCursor.

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().

skip(integer $num)

Wrapper method for MongoCursor::skip().

slaveOkay(boolean $ok = true)

Wrapper method for MongoCursor::slaveOkay().

snapshot()

Wrapper method for MongoCursor::snapshot().

sort(array $fields)

Wrapper method for MongoCursor::sort().

tailable(boolean $tail = true)

Wrapper method for MongoCursor::tailable().

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().

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()

Cursor addOption(string $key, mixed $value)

Wrapper method for MongoCursor::addOption().

Parameters

string $key
mixed $value

Return Value

Cursor

See also

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

Cursor batchSize(integer $num)

Wrapper method for MongoCursor::batchSize().

Parameters

integer $num

Return Value

Cursor

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

Cursor fields(array $f)

Wrapper method for MongoCursor::fields().

Parameters

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

Return Value

Cursor

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

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

Wrapper method for MongoCursor::setReadPreference().

Parameters

string $readPreference
array $tags

Return Value

Cursor

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}

Cursor 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

Cursor

See also

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

Cursor hydrate(boolean $hydrate = true)

Set whether to hydrate results as document class instances.

Parameters

boolean $hydrate

Return Value

Cursor

Cursor immortal(boolean $liveForever = true)

Wrapper method for MongoCursor::immortal().

Parameters

boolean $liveForever

Return Value

Cursor

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().

Cursor limit(integer $num)

Wrapper method for MongoCursor::limit().

Parameters

integer $num

Return Value

Cursor

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()

Cursor 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

Cursor

reset()

Wrapper method for MongoCursor::reset().

rewind()

Wrapper method for MongoCursor::rewind().

Cursor skip(integer $num)

Wrapper method for MongoCursor::skip().

Parameters

integer $num

Return Value

Cursor

See also

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

Cursor slaveOkay(boolean $ok = true)

Wrapper method for MongoCursor::slaveOkay().

Parameters

boolean $ok

Return Value

Cursor

See also

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

Cursor snapshot()

Wrapper method for MongoCursor::snapshot().

Return Value

Cursor

See also

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

Cursor sort(array $fields)

Wrapper method for MongoCursor::sort().

Field names will be prepared according to the document mapping.

Parameters

array $fields

Return Value

Cursor

See also

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

Cursor tailable(boolean $tail = true)

Wrapper method for MongoCursor::tailable().

Parameters

boolean $tail

Return Value

Cursor

See also

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

Cursor timeout(integer $ms)

Wrapper method for MongoCursor::timeout().

Parameters

integer $ms

Return Value

Cursor

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().

Cursor enableReferencePriming(array $primers, ReferencePrimer $referencePrimer)

Parameters

array $primers
ReferencePrimer $referencePrimer

Return Value

Cursor

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