Documentation

RepositoryInterface

Base interface for all repositories.

Repositories abstract database access and provide a collection-like interface for domain objects.

Tags
template

The entity type this repository manages

since
3.0.0

Table of Contents

Methods

count()  : int
Count entities matching criteria.
delete()  : bool
Delete an entity.
exists()  : bool
Check if an entity with the given ID exists.
find()  : object|null
Find an entity by its primary key.
findAll()  : array<int, object>
Find all entities.
findBy()  : array<int, object>
Find entities by criteria.
findOneBy()  : object|null
Find a single entity by criteria.
save()  : int
Save an entity (insert or update).

Methods

count()

Count entities matching criteria.

public count([array<string, mixed> $criteria = [] ]) : int
Parameters
$criteria : array<string, mixed> = []

Field => value pairs

Return values
int

The count

delete()

Delete an entity.

public delete(object|int $entityOrId) : bool
Parameters
$entityOrId : object|int

The entity or its ID

Tags
psalm-param

T|int $entityOrId

Return values
bool

True if deleted, false if not found

exists()

Check if an entity with the given ID exists.

public exists(int $id) : bool
Parameters
$id : int

The entity ID

Return values
bool

find()

Find an entity by its primary key.

public find(int $id) : object|null
Parameters
$id : int

The entity ID

Tags
psalm-return

T|null

Return values
object|null

The entity or null if not found

findAll()

Find all entities.

public findAll() : array<int, object>
Tags
psalm-return

array<int, T>

Return values
array<int, object>

Array of entities

findBy()

Find entities by criteria.

public findBy(array<string, mixed> $criteria[, array<string, string>|null $orderBy = null ][, int|null $limit = null ][, int|null $offset = null ]) : array<int, object>
Parameters
$criteria : array<string, mixed>

Field => value pairs

$orderBy : array<string, string>|null = null

Field => direction pairs

$limit : int|null = null

Maximum results

$offset : int|null = null

Offset for pagination

Tags
psalm-return

array<int, T>

Return values
array<int, object>

Array of matching entities

findOneBy()

Find a single entity by criteria.

public findOneBy(array<string, mixed> $criteria) : object|null
Parameters
$criteria : array<string, mixed>

Field => value pairs

Tags
psalm-return

T|null

Return values
object|null

The entity or null if not found

save()

Save an entity (insert or update).

public save(object $entity) : int
Parameters
$entity : object

The entity to save

Tags
psalm-param

T $entity

psalm-suppress

PossiblyUnusedReturnValue - Return value is optional; useful for inserts

Return values
int

The entity ID (useful for inserts)


        
On this page

Search results