Documentation

AbstractRepository implements RepositoryInterface

AbstractYes

Abstract base class for repositories.

Provides common CRUD functionality using the QueryBuilder with prepared statements for security.

Tags
template

The entity type this repository manages

implements
since
3.0.0

Table of Contents

Interfaces

RepositoryInterface
Base interface for all repositories.

Properties

$columnMap  : array<string, string>
Column mapping: entity property => database column.
$primaryKey  : string
The primary key column name.
$tableName  : string
The table name (without prefix).

Methods

beginTransaction()  : bool
Begin a database transaction.
commit()  : bool
Commit the current transaction.
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.
rollback()  : bool
Rollback the current transaction.
save()  : int
Save an entity (insert or update).
getEntityId()  : int
Get the ID from an entity.
mapToEntity()  : object
Map a database row to an entity object.
mapToRow()  : array<string, scalar|null>
Map an entity to a database row.
query()  : QueryBuilder
Get a query builder for this repository's table.
setEntityId()  : void
Set the ID on an entity.

Properties

$columnMap

Column mapping: entity property => database column.

protected array<string, string> $columnMap = []

Methods

beginTransaction()

Begin a database transaction.

public beginTransaction() : bool
Return values
bool

commit()

Commit the current transaction.

public commit() : bool
Return values
bool

count()

Count entities matching criteria.

public count([array<string, mixed> $criteria = [] ]) : int
Parameters
$criteria : array<string, mixed> = []
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-suppress

MoreSpecificImplementedParamType

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

InvalidReturnStatement

Return values
object|null

The entity or null if not found

findAll()

Find all entities.

public findAll() : array<int, object>
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>
$orderBy : array<string, string>|null = null
$limit : int|null = null

Maximum results

$offset : int|null = null

Offset for pagination

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

InvalidReturnStatement

psalm-return

T|null

Return values
object|null

rollback()

Rollback the current transaction.

public rollback() : bool
Return values
bool

save()

Save an entity (insert or update).

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

The entity to save

Tags
psalm-suppress

MoreSpecificImplementedParamType

psalm-suppress

PossiblyUnusedReturnValue - Return value is optional; useful for inserts

Return values
int

The entity ID (useful for inserts)

getEntityId()

Get the ID from an entity.

protected abstract getEntityId(object $entity) : int
Parameters
$entity : object

The entity

Tags
psalm-param

T $entity

Return values
int

The entity ID

mapToEntity()

Map a database row to an entity object.

protected abstract mapToEntity(array<string, mixed> $row) : object
Parameters
$row : array<string, mixed>

Database row

Tags
psalm-return

T

Return values
object

The entity

mapToRow()

Map an entity to a database row.

protected abstract mapToRow(object $entity) : array<string, scalar|null>
Parameters
$entity : object

The entity

Tags
psalm-param

T $entity

Return values
array<string, scalar|null>

Database row data

setEntityId()

Set the ID on an entity.

protected abstract setEntityId(object $entity, int $id) : void
Parameters
$entity : object

The entity

$id : int

The ID to set

Tags
psalm-param

T $entity


        
On this page

Search results