Nextcloud PHP API (master)

Repository
in package

Tags
template
since
35.0.0

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
since
35.0.0
psalm-suppress

InvalidConstantAssignmentValue

Properties

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

T $entity

since
35.0.0

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
throws
Exception
since
35.0.0
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
note

If you need to implement pagination, prefer using findByAfterId instead.

since
35.0.0
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
warning

This does not support tables with composite primary keys

throws
LogicException

if the entity has a composite primary key

since
35.0.0
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
warning

This does not support tables with composite primary keys

throws
LogicException

if the entity has a composite primary key

since
35.0.0
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
throws
DoesNotExistException
since
35.0.0
Return values
T

getTableName()

public getTableName() : string
Tags
since
35.0.0
Return values
string

insert()

Inserts the entity and populates its generated primary key.

public insert(object $entity) : T
Parameters
$entity : object
Tags
psalm-param

T $entity

throws
Exception
since
35.0.0
Return values
T

insertOrUpdate()

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
throws
Exception
InvalidArgumentException

if entity has no id

since
15.0.0
Return values
T

the saved entity with the (new) id

update()

public update(object $entity) : T
Parameters
$entity : object
Tags
psalm-param

T $entity

since
35.0.0
Return values
T

yieldAll()

public yieldAll() : Generator<string|int, T>
Tags
throws
Exception
since
35.0.0
Return values
Generator<string|int, T>

buildJoinedSelectQuery()

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}>}

getEntityClass()

private getEntityClass() : class-string
Return values
class-string

getJoinedSelectQueryBuilder()

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
template
Return values
S

isGeneratedIdColumn()

private isGeneratedIdColumn(EntityInfo $entityInfo, string $column) : bool
Parameters
$entityInfo : EntityInfo
$column : string
Return values
bool

joinRelation()

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
T

yieldJoinedEntities()

private yieldJoinedEntities(IQueryBuilder $query, array<string, EntityInfo}$relations) : Generator<string|int, T>
Parameters
$query : IQueryBuilder
$relations : array<string, EntityInfo}>
Return values
Generator<string|int, T>
On this page

Search results