Repository
in package
Tags
Table of Contents
Constants
- entityClass : string = ''
- The class this repository holds.
Properties
- $connection : IDBConnection
- $entityManager : EntityManager
- $entityClassOverride : string|null
Methods
- delete() : void
- deleteBy() : int
- findBy() : Generator<string|int, T>
- Finds entities by a set of criteria, keyed by property name.
- findByAfterId() : Generator<string|int, T>
- Finds entities by a set of criteria, keyed by property name, one page at a time ordered by their primary key — using keyset (seek) pagination instead of OFFSET/LIMIT.
- findByBeforeId() : Generator<string|int, T>
- Finds entities by a set of criteria, keyed by property name, one page at a time ordered by their primary key in descending order — using keyset (seek) pagination instead of OFFSET/LIMIT.
- findOneBy() : T
- Finds a single entity by a set of criteria, keyed by property name.
- getTableName() : string
- insert() : T
- Inserts the entity and populates its generated primary key.
- insertOrUpdate() : T
- Tries to create a new entry in the db from an entity and updates an existing entry if duplicate keys are detected by the database
- update() : T
- yieldAll() : Generator<string|int, T>
- buildDebugMessage() : string
- buildJoinedSelectQuery() : EntityInfo}>}
- Builds a select query resolving OneToOne and ManyToOne relations via a LEFT JOIN.
- findJoinedEntity() : T
- getEntityClass() : class-string
- getJoinedSelectQueryBuilder() : EntityInfo}>}
- hydrateRow() : S
- Builds an entity from a flat row of its own scalar columns. OneToOne relations are always left null here; resolving them is mapJoinedRowToEntity()'s job.
- isGeneratedIdColumn() : bool
- joinRelation() : void
- mapJoinedRowToEntity() : T
- yieldJoinedEntities() : Generator<string|int, T>
Constants
entityClass
The class this repository holds.
public
string
entityClass
= ''
Tags
Properties
$connection read-only
protected
IDBConnection
$connection
$entityManager read-only
protected
EntityManager
$entityManager
$entityClassOverride read-only
private
string|null
$entityClassOverride
= null
Methods
delete()
public
delete(object $entity) : void
Parameters
- $entity : object
Tags
deleteBy()
public
deleteBy(array<string, int|float|string|null|DateTime|BackedEnum|array<int, int|float|string|BackedEnum>> $criteria[, int|null $limit = null ]) : int
Parameters
- $criteria : array<string, int|float|string|null|DateTime|BackedEnum|array<int, int|float|string|BackedEnum>>
- $limit : int|null = null
Tags
Return values
int —The number of rows deleted
findBy()
Finds entities by a set of criteria, keyed by property name.
public
findBy(array<string, int|float|string|null|DateTime|BackedEnum|array<int, int|float|string|BackedEnum>> $criteria[, array<string, SortDirection> $orderBy = [] ][, int|null $limit = null ][, int|null $offset = null ]) : Generator<string|int, T>
Parameters
- $criteria : array<string, int|float|string|null|DateTime|BackedEnum|array<int, int|float|string|BackedEnum>>
- $orderBy : array<string, SortDirection> = []
- $limit : int|null = null
- $offset : int|null = null
Tags
Return values
Generator<string|int, T>findByAfterId()
Finds entities by a set of criteria, keyed by property name, one page at a time ordered by their primary key — using keyset (seek) pagination instead of OFFSET/LIMIT.
public
findByAfterId(array<string, int|float|string|null|DateTime|BackedEnum|array<int, int|float|string|BackedEnum>> $criteria, int|string|null $lastId, int $limit) : Generator<string|int, T>
Unlike findBy()'s $offset, which forces the database to scan and discard every preceding row on every call, $lastId lets it seek straight to the right spot through the primary key's index, so each page costs the same regardless of how deep it is. Pass null to fetch the first page, then the id of the last entity returned to fetch the next one; stop once fewer than $limit entities come back.
Parameters
- $criteria : array<string, int|float|string|null|DateTime|BackedEnum|array<int, int|float|string|BackedEnum>>
- $lastId : int|string|null
-
The primary key of the last entity from the previous page, or null to fetch the first page.
- $limit : int
Tags
Return values
Generator<string|int, T>findByBeforeId()
Finds entities by a set of criteria, keyed by property name, one page at a time ordered by their primary key in descending order — using keyset (seek) pagination instead of OFFSET/LIMIT.
public
findByBeforeId(array<string, int|float|string|null|DateTime|BackedEnum|array<int, int|float|string|BackedEnum>> $criteria, int|string|null $lastId, int $limit) : Generator<string|int, T>
This is the mirror image of findByAfterId(), walking from the highest id downwards instead of from the lowest id upwards. Pass null to fetch the first page (starting from the highest id), then the id of the last entity returned to fetch the next one; stop once fewer than $limit entities come back.
Parameters
- $criteria : array<string, int|float|string|null|DateTime|BackedEnum|array<int, int|float|string|BackedEnum>>
- $lastId : int|string|null
-
The primary key of the last entity from the previous page, or null to fetch the first page.
- $limit : int
Tags
Return values
Generator<string|int, T>findOneBy()
Finds a single entity by a set of criteria, keyed by property name.
public
findOneBy(array<string, int|float|string|null|DateTime|BackedEnum|array<int, int|float|string|BackedEnum>> $criteria[, array<string, SortDirection> $orderBy = [] ]) : T
Parameters
- $criteria : array<string, int|float|string|null|DateTime|BackedEnum|array<int, int|float|string|BackedEnum>>
- $orderBy : array<string, SortDirection> = []
Tags
Return values
TgetTableName()
public
getTableName() : string
Tags
Return values
stringinsert()
Inserts the entity and populates its generated primary key.
public
insert(object $entity) : T
Parameters
- $entity : object
Tags
Return values
TinsertOrUpdate()
Tries to create a new entry in the db from an entity and updates an existing entry if duplicate keys are detected by the database
public
insertOrUpdate(T $entity) : T
Parameters
- $entity : T
-
the entity that should be created/updated
Tags
Return values
T —the saved entity with the (new) id
update()
public
update(object $entity) : T
Parameters
- $entity : object
Tags
Return values
TyieldAll()
public
yieldAll() : Generator<string|int, T>
Tags
Return values
Generator<string|int, T>buildDebugMessage()
private
buildDebugMessage(string $msg, IQueryBuilder $sql) : string
Parameters
- $msg : string
- $sql : IQueryBuilder
Return values
stringbuildJoinedSelectQuery()
Builds a select query resolving OneToOne and ManyToOne relations via a LEFT JOIN.
private
buildJoinedSelectQuery(EntityInfo $entityInfo) : EntityInfo}>}
Columns are aliased e_<column> (main entity) and r<index>_<column> (each relation)
to stay unique even when tables share column names.
Parameters
- $entityInfo : EntityInfo
Return values
EntityInfo}>}findJoinedEntity()
private
findJoinedEntity(IQueryBuilder $query, array<string, EntityInfo}> $relations) : T
Parameters
- $query : IQueryBuilder
- $relations : array<string, EntityInfo}>
Tags
Return values
TgetEntityClass()
private
getEntityClass() : class-string
Return values
class-stringgetJoinedSelectQueryBuilder()
private
getJoinedSelectQueryBuilder(array<string, int|float|string|null|DateTime|BackedEnum|array<int, int|float|string|BackedEnum>> $criteria[, array<string, SortDirection> $orderBy = [] ]) : EntityInfo}>}
Parameters
- $criteria : array<string, int|float|string|null|DateTime|BackedEnum|array<int, int|float|string|BackedEnum>>
- $orderBy : array<string, SortDirection> = []
Return values
EntityInfo}>}hydrateRow()
Builds an entity from a flat row of its own scalar columns. OneToOne relations are always left null here; resolving them is mapJoinedRowToEntity()'s job.
private
hydrateRow(S> $entityClass, array<string, mixed> $row) : S
Parameters
- $entityClass : S>
- $row : array<string, mixed>
Tags
Return values
SisGeneratedIdColumn()
private
isGeneratedIdColumn(EntityInfo $entityInfo, string $column) : bool
Parameters
- $entityInfo : EntityInfo
- $column : string
Return values
booljoinRelation()
private
joinRelation(IQueryBuilder $qb, string $alias, EntityInfo $targetEntityInfo, string $leftExpr, string $rightExpr) : void
Parameters
- $qb : IQueryBuilder
- $alias : string
- $targetEntityInfo : EntityInfo
- $leftExpr : string
- $rightExpr : string
mapJoinedRowToEntity()
private
mapJoinedRowToEntity(array<string, EntityInfo}> $relations, array<string, mixed> $row) : T
Parameters
- $relations : array<string, EntityInfo}>
- $row : array<string, mixed>
Return values
TyieldJoinedEntities()
private
yieldJoinedEntities(IQueryBuilder $query, array<string, EntityInfo}> $relations) : Generator<string|int, T>
Parameters
- $query : IQueryBuilder
- $relations : array<string, EntityInfo}>