Skip to content
docsv0.1.0

InMemoryRepository

Array-backed {@see RepositoryInterface}: same contract as {@see FileRepository}, kept entirely in process memory — for tests and zero-file consumers. Nothing is written to disk and nothing survives past the instance's lifetime.

InMemoryRepository::__construct()

public function __construct(string $entityClass):

Parameters

Parameters of __construct()
NameTypeDescription
$entityClassclass-string<T>the entity class rows are rehydrated into via `fromArray()`

InMemoryRepository::find()

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

InMemoryRepository::save()

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

Persists `$entity` in memory. When `$entity->id()` is `null`, a fresh id is assigned via {@see self::nextId()}. The stored row always carries the id actually used under the key `'id'`, regardless of what `$entity->toArray()` returned for it.

Parameters

Parameters of save()
NameTypeDescription
$entityT

InMemoryRepository::delete()

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

InMemoryRepository::all()

public function all(): array

Every stored entity, in insertion order.

InMemoryRepository::nextId()

public function nextId(): 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.

InMemoryRepository::query()

public function query(array $criteria): array

Stored entities matching every `$criteria` pair by strict equality.

Parameters

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