Skip to content
docsv0.3.0

Event

Immutable fact appended to an {@see EventStoreInterface}'s log. A stream's state is never stored directly — it is always the fold of its `Event`s, so this VO is the only unit of truth an event store persists. `streamId` groups events into independent, individually replayable streams (a process instance, an aggregate, an entity id — any identifier the consumer chooses to partition its log by). `type` is a free-form name the consumer defines and interprets; the store itself never inspects it. `recordedAt` is the wall-clock observation made by the process constructing the event. It is not a verified occurrence time or a duration: its trust is exactly the trust placed in that process and its clock. A `null` value is reserved for records written before this observation existed; readers must preserve that gap rather than manufacture a time from file metadata or payload contents.

Event::__construct()

public function __construct(string $streamId, string $type, array $payload, int $seq, ?DateTimeImmutable $recordedAt = new DateTimeImmutable()):

Parameters

Parameters of __construct()
NameTypeDescription
$streamIdstringthe stream this event belongs to
$typestringthe event's name, defined and interpreted by the consumer
$payloadarray<string, mixed>data carried by this event
$seqintmonotonic position of this event within its event store
$recordedAt?\DateTimeImmutablewall-clock observation by the constructing process; `null` means the record predates this field

Event::toArray()

public function toArray(): array

Projects this event into a plain array suitable for JSON encoding (JSONL round-trip).

Event::fromArray()

public static function fromArray(array $row): self

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

Parameters

Parameters of fromArray()
NameTypeDescription
$rowarray{stream_id: string, type: string, payload: array<string, mixed>, seq: int, recorded_at?: ?string}