Skip to content
docsv0.1.0

EntityInterface

A plain domain object that round-trips through persistence via {@see self::toArray()} / {@see self::fromArray()} — no base class, no attributes, no ORM coupling; any final class can implement it, the way the `example-agent-ready-blog`'s `Post` does. Conventionally the array returned by `toArray()` carries the identity under the key `'id'`, mirroring {@see self::id()} — {@see FileRepository} and {@see InMemoryRepository} rely on that key when assigning a fresh id to an entity saved without one.

EntityInterface::id()

abstract public function id(): string|int|null

This entity's identity, or `null` when it has never been saved — an id is assigned the first time it is passed to {@see RepositoryInterface::save()}.

EntityInterface::toArray()

abstract public function toArray(): array

Projects this entity into a plain array suitable for JSON encoding or any other serialization.

EntityInterface::fromArray()

abstract public static function fromArray(array $row): static

Reconstructs an entity from the array shape produced by {@see self::toArray()}.

Parameters

Parameters of fromArray()
NameTypeDescription
$rowarray<string, mixed>