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\EntityInterfaceThe entity stored under `$id`, or `null` when no entity is stored under it.
Parameters
| Name | Type | Description |
|---|---|---|
| $id | string|int |
RepositoryInterface::save()
abstract public function save(Milpa\Data\EntityInterface $entity): string|intPersists `$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
| Name | Type | Description |
|---|---|---|
| $entity | T |
RepositoryInterface::delete()
abstract public function delete(string|int $id): voidRemoves the entity stored under `$id`. A no-op when no entity is stored under it.
Parameters
| Name | Type | Description |
|---|---|---|
| $id | string|int |
RepositoryInterface::all()
abstract public function all(): arrayEvery stored entity, in insertion order.
RepositoryInterface::nextId()
abstract public function nextId(): string|intThe 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): arrayStored 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
| Name | Type | Description |
|---|---|---|
| $criteria | array<string, mixed> |