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 $classMetadata)

Initializes this instance with the specified document manager, unit of work and class metadata.

createQueryBuilder()

Creates a new Query\Builder instance that is preconfigured for this document name.

createAggregationBuilder()

Creates a new Aggregation\Builder instance that is prepopulated for this document name.

clear()

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

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

Finds a document matching the specified identifier. Optionally a lock mode and expected version may be specified.

array
findAll()

Finds all documents in the repository.

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

Finds documents by a set of criteria.

object
findOneBy(array $criteria)

Finds a single document by a set of criteria.

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 $classMetadata)

Initializes this instance with the specified document manager, unit of work and class metadata.

Parameters

DocumentManager $dm The DocumentManager to use.
UnitOfWork $uow The UnitOfWork to use.
ClassMetadata $classMetadata The class metadata.

Builder createQueryBuilder()

Creates a new Query\Builder instance that is preconfigured for this document name.

Return Value

Builder $qb

Builder createAggregationBuilder()

Creates a new Aggregation\Builder instance that is prepopulated for this document name.

Return Value

Builder

clear()

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

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

Finds a document matching the specified identifier. Optionally a lock mode and expected version may be specified.

Parameters

mixed $id Identifier.
int $lockMode Optional. Lock mode; one of the LockMode constants.
int $lockVersion Optional. Expected version.

Return Value

object|null The document, if found, otherwise null.

Exceptions

MappingException
LockException

array findAll()

Finds all documents in the repository.

Return Value

array

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

Finds documents by a set of criteria.

Parameters

array $criteria Query criteria
array|null $sort Sort array for Cursor::sort()
int|null $limit Limit for Cursor::limit()
int|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

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