class DocumentRepository implements ObjectRepository (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.

Constants

QUERY_REPLACE_WITH_FIELDNAMES

Properties

protected DocumentManagerInterface $dm
protected ClassMetadata $class
protected UnitOfWork $uow
protected string $className

Methods

__construct(DocumentManagerInterface $dm, ClassMetadata $class)

Initializes a new DocumentRepository.

object
find(string $id)

Find a single document by its id.

array
findMany(array $ids)

Find many document by id.

array
findAll()

Finds all documents in the repository.

array
findBy(array $criteria, array $orderBy = null, int|null $limit = null, int|null $offset = null)

Finds document by a set of criteria.

constraintField(ConstraintFactory $where, string $field, mixed $value, string $alias)

Constraints a field for a given value.

object|null
findOneBy(array $criteria)

Finds a single document by a set of criteria.

refresh(object $document)

Refresh a document with the data from PHPCR.

refreshDocumentForProxy(object $document)

No description

string
getClassName()

Get the document class name this repository is for.

getClassMetadata()

No description

string
quote(string $val, int $type = null)

Quote a string for inclusion in an SQL2 query.

string
escapeFullText(string $string)

Escape the illegal characters for inclusion in an SQL2 query. Escape Character is \.

createQuery($statement, $language, $options = 0)

Create a Query.

createQueryBuilder(string $alias)

Create a QueryBuilder that is pre-populated for this repositories document.

Details

__construct(DocumentManagerInterface $dm, ClassMetadata $class)

Initializes a new DocumentRepository.

Parameters

DocumentManagerInterface $dm The DocumentManager to use.
ClassMetadata $class The class descriptor.

object find(string $id)

Find a single document by its id.

The id may either be a PHPCR path or UUID

Parameters

string $id document id

Return Value

object document or null

array findMany(array $ids)

Find many document by id.

The ids may either be PHPCR paths or UUID's, but all must be of the same type

Parameters

array $ids document ids

Return Value

array of document objects

array findAll()

Finds all documents in the repository.

Return Value

array The entities.

array findBy(array $criteria, array $orderBy = null, int|null $limit = null, int|null $offset = null)

Finds document by a set of criteria.

Optionally sorting and limiting details can be passed. An implementation may throw an InvalidArgumentException if certain values of the sorting or limiting details are not supported.

Parameters

array $criteria
array $orderBy
int|null $limit
int|null $offset

Return Value

array The objects matching the criteria.

protected constraintField(ConstraintFactory $where, string $field, mixed $value, string $alias)

Constraints a field for a given value.

Parameters

ConstraintFactory $where
string $field The field searched
mixed $value The value to search for
string $alias The alias used

object|null findOneBy(array $criteria)

Finds a single document by a set of criteria.

Parameters

array $criteria

Return Value

object|null The first document matching the criteria or null if none found

refresh(object $document)

Refresh a document with the data from PHPCR.

Parameters

object $document

refreshDocumentForProxy(object $document)

Parameters

object $document

string getClassName()

Get the document class name this repository is for.

Return Value

string

DocumentManagerInterface getDocumentManager()

ClassMetadata getClassMetadata()

Return Value

ClassMetadata

string quote(string $val, int $type = null)

Quote a string for inclusion in an SQL2 query.

Parameters

string $val
int $type

Return Value

string the quoted value

See also

PropertyType

string escapeFullText(string $string)

Escape the illegal characters for inclusion in an SQL2 query. Escape Character is \.

Parameters

string $string

Return Value

string Escaped String

See also

http://jackrabbit.apache.org/api/1.4/org/apache/jackrabbit/util/Text.html #escapeIllegalJcrChars

Query createQuery($statement, $language, $options = 0)

Create a Query.

Parameters

$statement
$language
$options

Return Value

Query

QueryBuilder createQueryBuilder(string $alias)

Create a QueryBuilder that is pre-populated for this repositories document.

The returned query builder will be pre-populated with the criteria required to search for this repositories document class.

NOTE: When adding criteria to the query builder you should use ->andWhere(...) as ->where(...) will overwrite the class criteria.

Parameters

string $alias name of the alias to use, defaults to 'a'

Return Value

QueryBuilder