Documentation

ServiceEntityRepository extends EntityRepository
in package
implements ServiceEntityRepositoryInterface

Optional EntityRepository base class with a simplified constructor (for autowiring).

To use in your class, inject the "registry" service and call the parent constructor. For example:

class YourEntityRepository extends ServiceEntityRepository { public function __construct(ManagerRegistry $registry) { parent::__construct($registry, YourEntity::class); } }

Tags
template

T of object

template-extends

EntityRepository<T>

Table of Contents

Interfaces

ServiceEntityRepositoryInterface
This interface signals that your repository should be loaded from the container.

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

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
psalm-param

list $arguments

throws
BadMethodCallException

If the method called is invalid.

Return values
mixed

The returned value from the resolved method.

__construct()

public __construct(ManagerRegistry $registry, string $entityClass) : mixed
Parameters
$registry : ManagerRegistry
$entityClass : string

The class name of the entity this repository manages

Tags
psalm-param

class-string<T> $entityClass

clear()

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

public clear() : void
Tags
deprecated
2.8

This method is being removed from the ORM and won't have any replacement

count()

Counts entities by a set of criteria.

public count(array<string|int, mixed> $criteria) : int
Parameters
$criteria : array<string|int, mixed>
Tags
psalm-param

array<string, mixed> $criteria

todo

Add this method to ObjectRepository interface in the next major release

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
deprecated
Return values
Query

createNativeNamedQuery()

Creates a native SQL query.

public createNativeNamedQuery(string $queryName) : NativeQuery
Parameters
$queryName : string
Tags
deprecated
Return values
NativeQuery

createQueryBuilder()

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
QueryBuilder

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
psalm-param

LockMode::*|null $lockMode

psalm-return

?T

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
psalm-return

list<T> The entities.

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
psalm-param

array<string, mixed> $criteria

psalm-param

array<string, string>|null $orderBy

psalm-return

list<T>

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
psalm-param

array<string, mixed> $criteria

psalm-param

array<string, string>|null $orderBy

psalm-return

?T

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

getEntityName()

protected getEntityName() : string
Tags
psalm-return

class-string<T>

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>
Tags
psalm-param

list $arguments The arguments to pass at method call

throws
InvalidMagicMethodCall

If the method called is invalid or the requested field/association does not exist.


        
On this page

Search results