class EntityRepository implements ObjectRepository, Selectable (View source)

An EntityRepository serves as a repository for entities with generic as well as business specific methods for retrieving entities.

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

Properties

protected string $_entityName
protected EntityManager $_em
protected ClassMetadata $_class

Methods

__construct(EntityManagerInterface $em, ClassMetadata $class)

Initializes a new EntityRepository.

createQueryBuilder(string $alias, string $indexBy = null)

Creates a new QueryBuilder instance that is prepopulated for this entity name.

createResultSetMappingBuilder(string $alias)

Creates a new result set mapping builder for this entity.

createNamedQuery(string $queryName)

Creates a new Query instance based on a predefined metadata named query.

createNativeNamedQuery(string $queryName)

Creates a native SQL query.

void
clear()

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

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

Finds an entity by its primary key / identifier.

array
findAll()

Finds all entities in the repository.

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

Finds entities by a set of criteria.

object|null
findOneBy(array $criteria, array $orderBy = null)

Finds a single entity by a set of criteria.

int
count(array $criteria)

Counts entities by a set of criteria.

mixed
__call(string $method, array $arguments)

Adds support for magic method calls.

string
getEntityName()

No description

string
getClassName()

No description

getEntityManager()

No description

getClassMetadata()

No description

Collection
matching(Criteria $criteria)

Select all elements from a selectable that match the expression and return a new collection containing these elements.

Details

__construct(EntityManagerInterface $em, ClassMetadata $class)

Initializes a new EntityRepository.

Parameters

EntityManagerInterface $em The EntityManager to use.
ClassMetadata $class The class descriptor.

QueryBuilder createQueryBuilder(string $alias, string $indexBy = null)

Creates a new QueryBuilder instance that is prepopulated for this entity name.

Parameters

string $alias
string $indexBy The index for the from.

Return Value

QueryBuilder

ResultSetMappingBuilder createResultSetMappingBuilder(string $alias)

Creates a new result set mapping builder for this entity.

The column naming strategy is "INCREMENT".

Parameters

string $alias

Return Value

ResultSetMappingBuilder

Query createNamedQuery(string $queryName)

Creates a new Query instance based on a predefined metadata named query.

Parameters

string $queryName

Return Value

Query

NativeQuery createNativeNamedQuery(string $queryName)

Creates a native SQL query.

Parameters

string $queryName

Return Value

NativeQuery

void clear()

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

Return Value

void

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

Finds an entity by its primary key / identifier.

Parameters

mixed $id The identifier.
int|null $lockMode One of the \Doctrine\DBAL\LockMode::* constants or NULL if no specific lock mode should be used during the search.
int|null $lockVersion The lock version.

Return Value

object|null The entity instance or NULL if the entity can not be found.

array findAll()

Finds all entities in the repository.

Return Value

array The entities.

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

Finds entities by a set of criteria.

Parameters

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

Return Value

array The objects.

object|null findOneBy(array $criteria, array $orderBy = null)

Finds a single entity by a set of criteria.

Parameters

array $criteria
array $orderBy

Return Value

object|null The entity instance or NULL if the entity can not be found.

int count(array $criteria)

Counts entities by a set of criteria.

Parameters

array $criteria

Return Value

int The cardinality of the objects that match the given criteria.

mixed __call(string $method, array $arguments)

Adds support for magic method calls.

Parameters

string $method
array $arguments

Return Value

mixed The returned value from the resolved method.

Exceptions

ORMException
BadMethodCallException If the method called is invalid

protected string getEntityName()

Return Value

string

string getClassName()

Return Value

string

protected EntityManager getEntityManager()

Return Value

EntityManager

protected ClassMetadata getClassMetadata()

Return Value

ClassMetadata

Collection matching(Criteria $criteria)

Select all elements from a selectable that match the expression and return a new collection containing these elements.

Parameters

Criteria $criteria

Return Value

Collection