Skip to content
docsv0.1.0

RepositoryInterface

A persistence boundary for one entity type: plain data in, plain data out, equality-only querying — no query language, no relations, no transactions. One repository instance is bound to exactly one entity class (the concrete `T`); a consumer with several persistent entity types wires one repository per type. {@see FileRepository} and {@see InMemoryRepository} are the two backends behind this contract.

RepositoryInterface::find()

abstract public function find(string|int $id): ?Milpa\Data\EntityInterface

The entity stored under `$id`, or `null` when no entity is stored under it.

Parameters

Parameters of find()
NameTypeDescription
$idstring|int

RepositoryInterface::save()

abstract public function save(Milpa\Data\EntityInterface $entity): string|int

Persists `$entity`. When `$entity->id()` is `null`, a fresh id is assigned via {@see self::nextId()} before writing; the id actually used — freshly assigned, or the entity's own — is what gets returned.

Parameters

Parameters of save()
NameTypeDescription
$entityT

RepositoryInterface::delete()

abstract public function delete(string|int $id): void

Removes the entity stored under `$id`. A no-op when no entity is stored under it.

Parameters

Parameters of delete()
NameTypeDescription
$idstring|int

RepositoryInterface::all()

abstract public function all(): array

Every stored entity, in insertion order.

RepositoryInterface::nextId()

abstract public function nextId(): string|int

The id to assign to the next entity saved without one of its own — one past the highest integer id currently stored, or `1` when the store holds no integer id.

RepositoryInterface::query()

abstract public function query(array $criteria): array

Stored entities matching every `$criteria` pair by strict equality — `['status' => 'published']` matches entities whose `toArray()['status'] === 'published'`. An empty `$criteria` matches every entity, same as {@see self::all()}.

Parameters

Parameters of query()
NameTypeDescription
$criteriaarray<string, mixed>