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
| Name | Type | Description |
|---|---|---|
| $entityClass | class-string<T> | the entity class rows are rehydrated into via `fromArray()` |
InMemoryRepository::find()
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 |
InMemoryRepository::save()
public function save(Milpa\Data\EntityInterface $entity): string|intPersists `$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
| Name | Type | Description |
|---|---|---|
| $entity | T |
InMemoryRepository::delete()
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 |
InMemoryRepository::all()
public function all(): arrayEvery stored entity, in insertion order.
InMemoryRepository::nextId()
public function nextId(): 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.
InMemoryRepository::query()
public function query(array $criteria): arrayStored entities matching every `$criteria` pair by strict equality.
Parameters
| Name | Type | Description |
|---|---|---|
| $criteria | array<string, mixed> |