EntityRepository
in package
implements
ObjectRepository, Selectable
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.
Tags
Interfaces, Classes, Traits and Enums
- ObjectRepository
- Contract for a Doctrine persistence layer ObjectRepository class to implement.
- Selectable
- Interface for collections that allow efficient filtering with an expression API.
Table of Contents
- $_class : ClassMetadata
- $_em : EntityManager
- $_entityName : string
- $inflector : Inflector
- __call() : mixed
- Adds support for magic method calls.
- __construct() : mixed
- Initializes a new <tt>EntityRepository</tt>.
- clear() : void
- Clears the repository, causing all managed entities to become detached.
- count() : int
- Counts entities by a set of criteria.
- createNamedQuery() : Query
- Creates a new Query instance based on a predefined metadata named query.
- createNativeNamedQuery() : NativeQuery
- Creates a native SQL query.
- createQueryBuilder() : QueryBuilder
- Creates a new QueryBuilder instance that is prepopulated for this entity name.
- createResultSetMappingBuilder() : ResultSetMappingBuilder
- Creates a new result set mapping builder for this entity.
- find() : object|null
- Finds an entity by its primary key / identifier.
- findAll() : array<int, object>
- Finds all entities in the repository.
- findBy() : array<string|int, object>
- Finds entities by a set of criteria.
- findOneBy() : object|null
- Finds a single entity by a set of criteria.
- getClassName() : string
- Returns the class name of the object managed by the repository.
- matching() : LazyCriteriaCollection
- Select all elements from a selectable that match the expression and return a new collection containing these elements.
- getClassMetadata() : ClassMetadata
- getEntityManager() : EntityManager
- getEntityName() : string
- resolveMagicCall() : mixed
- Resolves a magic method call to the proper existent method at `EntityRepository`.
Properties
$_class
protected
ClassMetadata
$_class
$_em
protected
EntityManager
$_em
$_entityName
protected
string
$_entityName
$inflector
private
static Inflector
$inflector
Methods
__call()
Adds support for magic method calls.
public
__call(string $method, array<string|int, mixed> $arguments) : mixed
Parameters
- $method : string
- $arguments : array<string|int, mixed>
Tags
Return values
mixed —The returned value from the resolved method.
__construct()
Initializes a new <tt>EntityRepository</tt>.
public
__construct(EntityManagerInterface $em, ClassMetadata $class) : mixed
Parameters
- $em : EntityManagerInterface
- $class : ClassMetadata
Return values
mixed —clear()
Clears the repository, causing all managed entities to become detached.
public
clear() : void
Tags
Return values
void —count()
Counts entities by a set of criteria.
public
count(array<string|int, mixed> $criteria) : int
Parameters
- $criteria : array<string|int, mixed>
Tags
Return values
int —The cardinality of the objects that match the given criteria.
createNamedQuery()
Creates a new Query instance based on a predefined metadata named query.
public
createNamedQuery(string $queryName) : Query
Parameters
- $queryName : string
Tags
Return values
Query —createNativeNamedQuery()
Creates a native SQL query.
public
createNativeNamedQuery(string $queryName) : NativeQuery
Parameters
- $queryName : string
Tags
Return values
NativeQuery —createQueryBuilder()
Creates a new QueryBuilder instance that is prepopulated for this entity name.
public
createQueryBuilder(string $alias[, string $indexBy = null ]) : QueryBuilder
Parameters
- $alias : string
- $indexBy : string = null
-
The index for the from.
Return values
QueryBuilder —createResultSetMappingBuilder()
Creates a new result set mapping builder for this entity.
public
createResultSetMappingBuilder(string $alias) : ResultSetMappingBuilder
The column naming strategy is "INCREMENT".
Parameters
- $alias : string
Return values
ResultSetMappingBuilder —find()
Finds an entity by its primary key / identifier.
public
find(mixed $id[, int|null $lockMode = null ][, int|null $lockVersion = null ]) : object|null
Parameters
- $id : mixed
-
The identifier.
- $lockMode : int|null = null
-
One of the \Doctrine\DBAL\LockMode::* constants or NULL if no specific lock mode should be used during the search.
- $lockVersion : int|null = null
-
The lock version.
Tags
Return values
object|null —The entity instance or NULL if the entity can not be found.
findAll()
Finds all entities in the repository.
public
findAll() : array<int, object>
Tags
Return values
array<int, object> —The objects.
findBy()
Finds entities by a set of criteria.
public
findBy(array<string|int, mixed> $criteria[, array<string|int, mixed>|null $orderBy = null ][, int|null $limit = null ][, int|null $offset = null ]) : array<string|int, object>
Parameters
- $criteria : array<string|int, mixed>
- $orderBy : array<string|int, mixed>|null = null
- $limit : int|null = null
- $offset : int|null = null
Tags
Return values
array<string|int, object> —The objects.
findOneBy()
Finds a single entity by a set of criteria.
public
findOneBy(array<string|int, mixed> $criteria[, array<string|int, mixed>|null $orderBy = null ]) : object|null
Parameters
- $criteria : array<string|int, mixed>
-
The criteria.
- $orderBy : array<string|int, mixed>|null = null
Tags
Return values
object|null —The entity instance or NULL if the entity can not be found.
getClassName()
Returns the class name of the object managed by the repository.
public
getClassName() : string
Return values
string —matching()
Select all elements from a selectable that match the expression and return a new collection containing these elements.
public
matching(Criteria $criteria) : LazyCriteriaCollection
Parameters
- $criteria : Criteria
Tags
Return values
LazyCriteriaCollection —getClassMetadata()
protected
getClassMetadata() : ClassMetadata
Return values
ClassMetadata —getEntityManager()
protected
getEntityManager() : EntityManager
Return values
EntityManager —getEntityName()
protected
getEntityName() : string
Return values
string —resolveMagicCall()
Resolves a magic method call to the proper existent method at `EntityRepository`.
private
resolveMagicCall(string $method, string $by, array<string|int, mixed> $arguments) : mixed
Parameters
- $method : string
-
The method to call
- $by : string
-
The property name used as condition
- $arguments : array<string|int, mixed>