Skip to content
docsv0.1.0

XhtmlStateTransferCodec

The plain (unsigned) {@see StateTransferCodecInterface}: encodes a {@see StateSnapshot} / {@see InteractionRequest} as a single `<milpa-state>` / `<milpa-interaction>` XHTML element carrying a base64-encoded JSON payload, and decodes it back. Tamper-evidence and replay protection are NOT provided here — this codec is the `$inner` layer {@see \Milpa\Live\Security\SignedXhtmlStateTransferCodec} wraps to add HMAC signing on top; use the signed codec directly whenever the envelope will round-trip through an untrusted client.

XhtmlStateTransferCodec::encodeState()

public function encodeState(Milpa\Live\ValueObjects\StateSnapshot $snapshot): string

Encodes `$snapshot` as a `<milpa-state>` element whose text content is the base64-encoded JSON of its id/name/version/data/meta.

Parameters

Parameters of encodeState()
NameTypeDescription
$snapshotMilpa\Live\ValueObjects\StateSnapshot

XhtmlStateTransferCodec::decodeState()

public function decodeState(string $encoded): Milpa\Live\ValueObjects\StateSnapshot

Parses `$encoded` as a single `<milpa-state>` XML element and decodes its payload back into a {@see StateSnapshot}. Throws `RuntimeException` for malformed XML, a wrong root tag, or invalid base64/JSON in the payload.

Parameters

Parameters of decodeState()
NameTypeDescription
$encodedstring

XhtmlStateTransferCodec::encodeInteraction()

public function encodeInteraction(Milpa\Live\ValueObjects\InteractionRequest $request): string

Encodes `$request` as a `<milpa-interaction>` element whose text content is the base64-encoded JSON of its id/name/action/state/payload/meta.

Parameters

Parameters of encodeInteraction()
NameTypeDescription
$requestMilpa\Live\ValueObjects\InteractionRequest

XhtmlStateTransferCodec::decodeInteraction()

public function decodeInteraction(string $encoded): Milpa\Live\ValueObjects\InteractionRequest

Parses `$encoded` as a single `<milpa-interaction>` XML element and decodes its payload back into an {@see InteractionRequest}. Throws `RuntimeException` for malformed XML, a wrong root tag, or invalid base64/JSON in the payload.

Parameters

Parameters of decodeInteraction()
NameTypeDescription
$encodedstring