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
Table of Contents
Interfaces
- ObjectRepository
- Contract for a Doctrine persistence layer ObjectRepository class to implement.
- Selectable
- Interface for collections that allow efficient filtering with an expression API.
Properties
- $inflector : Inflector|null
Methods
- __call() : mixed
- Adds support for magic method calls.
- __construct() : mixed
- 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() : mixed
- Returns the class name of the object managed by the repository.
- matching() : AbstractLazyCollection
- Select all elements from a selectable that match the expression and return a new collection containing these elements.
- getClassMetadata() : ClassMetadata
- getEntityManager() : EntityManagerInterface
- getEntityName() : string
- resolveMagicCall() : mixed
- Resolves a magic method call to the proper existent method at `EntityRepository`.
Properties
$inflector
private
static Inflector|null
$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()
public
__construct(EntityManagerInterface $em, ClassMetadata $class) : mixed
Parameters
- $em : EntityManagerInterface
- $class : ClassMetadata
Tags
clear()
Clears the repository, causing all managed entities to become detached.
public
clear() : void
Tags
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
QuerycreateNativeNamedQuery()
Creates a native SQL query.
public
createNativeNamedQuery(string $queryName) : NativeQuery
Parameters
- $queryName : string
Tags
Return values
NativeQuerycreateQueryBuilder()
Creates a new QueryBuilder instance that is prepopulated for this entity name.
public
createQueryBuilder(string $alias[, string|null $indexBy = null ]) : QueryBuilder
Parameters
- $alias : string
- $indexBy : string|null = null
-
The index for the from.
Return values
QueryBuildercreateResultSetMappingBuilder()
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
ResultSetMappingBuilderfind()
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() : mixed
matching()
Select all elements from a selectable that match the expression and return a new collection containing these elements.
public
matching(Criteria $criteria) : AbstractLazyCollection
Parameters
- $criteria : Criteria
Tags
Return values
AbstractLazyCollectiongetClassMetadata()
protected
getClassMetadata() : ClassMetadata
Tags
Return values
ClassMetadatagetEntityManager()
protected
getEntityManager() : EntityManagerInterface
Return values
EntityManagerInterfacegetEntityName()
protected
getEntityName() : string
Tags
Return values
stringresolveMagicCall()
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>