class DocumentRepository implements ObjectRepository, Selectable (View source)

A DocumentRepository serves as a repository for documents with generic as well as business specific methods for retrieving documents.

This class is designed for inheritance and users can subclass this class to write their own repositories with business-specific methods to locate documents.

Properties

protected string $documentName
protected DocumentManager $dm
protected UnitOfWork $uow
protected ClassMetadata $class

Methods

__construct(DocumentManager $dm, UnitOfWork $uow, ClassMetadata $class)

Initializes a new DocumentRepository.

createQueryBuilder()

Create a new Query\Builder instance that is prepopulated for this document name

clear()

Clears the repository, causing all managed documents to become detached.

object
find(string|object $id, int $lockMode = LockMode::NONE, int $lockVersion = null)

Finds a document by its identifier

array
findAll()

Finds all documents in the repository.

array
findBy(array $criteria, array $sort = null, integer|null $limit = null, integer|null $skip = null)

Finds documents by a set of criteria.

object
findOneBy(array $criteria)

Finds a single document by a set of criteria.

array|object
__call(string $method, array $arguments)

Adds support for magic finders.

string
getDocumentName()

No description

getClassMetadata()

No description

string
getClassName()

No description

Collection
matching(Criteria $criteria)

Selects all elements from a selectable that match the expression and returns a new collection containing these elements.

getDocumentPersister()

No description

Details

__construct(DocumentManager $dm, UnitOfWork $uow, ClassMetadata $class)

Initializes a new DocumentRepository.

Parameters

DocumentManager $dm
UnitOfWork $uow
ClassMetadata $class

Builder createQueryBuilder()

Create a new Query\Builder instance that is prepopulated for this document name

Return Value

Builder $qb

clear()

Clears the repository, causing all managed documents to become detached.

object find(string|object $id, int $lockMode = LockMode::NONE, int $lockVersion = null)

Finds a document by its identifier

Parameters

string|object $id The identifier
int $lockMode
int $lockVersion

Return Value

object The document.

Exceptions

MappingException
LockException

array findAll()

Finds all documents in the repository.

Return Value

array

array findBy(array $criteria, array $sort = null, integer|null $limit = null, integer|null $skip = null)

Finds documents by a set of criteria.

Parameters

array $criteria Query criteria
array $sort Sort array for Cursor::sort()
integer|null $limit Limit for Cursor::limit()
integer|null $skip Skip for Cursor::skip()

Return Value

array

object findOneBy(array $criteria)

Finds a single document by a set of criteria.

Parameters

array $criteria

Return Value

object

array|object __call(string $method, array $arguments)

Adds support for magic finders.

Parameters

string $method
array $arguments

Return Value

array|object The found document/documents.

Exceptions

MongoDBException
BadMethodCallException If the method called is an invalid find* method or no find* method at all and therefore an invalid method call.

string getDocumentName()

Return Value

string

DocumentManager getDocumentManager()

Return Value

DocumentManager

ClassMetadata getClassMetadata()

Return Value

ClassMetadata

string getClassName()

Return Value

string

Collection matching(Criteria $criteria)

Selects all elements from a selectable that match the expression and returns a new collection containing these elements.

Parameters

Criteria $criteria

Return Value

Collection

See also

Selectable::matching()

protected getDocumentPersister()