php-skir / runtime
PHP runtime support for Skir serialization and descriptors.
Requires
- php: ^8.3
Requires (Dev)
- laravel/pint: ^1.29
- phpunit/phpunit: ^12.5
Suggests
None
Provides
None
Conflicts
None
Replaces
None
This package is auto-updated.
Last update: 2026-11-10 21:34:41 UTC
README
Framework-agnostic PHP runtime support for Skir serialization and descriptors.
This package is intentionally small. Laravel-specific routing and client behavior live in separate packages.
Installation
composer require php-skir/runtime
What it provides
DenseJsonfor encoding Skir dense JSON values and decoding JSON values of either flavor.ReadableJsonfor encoding Skir readable JSON values.BinaryFormatfor encoding and decoding the Skir binary format.Type,Field, andVariantdescriptors for generated DTO metadata.EnumValuefor Skir enum constants and wrapper variants.MethodDescriptorfor generated SkirRPC method metadata.- Package-local
SkirRuntimeExceptionexceptions for invalid Skir values.
Dense JSON
use Skir\Runtime\DenseJson; use Skir\Runtime\Field; use Skir\Runtime\Type; $user = Type::struct([ Field::value('id', 0, Type::int32()), Field::value('name', 1, Type::string()), ]); $json = DenseJson::toJson($user, [ 'id' => 1, 'name' => 'Jane', ]); $data = DenseJson::fromJson($user, $json);
A struct, enum, field, variant or method can also carry what the schema calls it. This is descriptive only: tools such as the server's RPC Studio show it, and serialization ignores it.
$session = Type::struct( [Field::value('token', 0, Type::string(), doc: 'Send it as a bearer token.')], recordId: 'identity/identity.skir:Session', doc: 'What a client stores after signing in.', );
Struct values are encoded as field-number indexed arrays. Removed fields and sparse field numbers are preserved so generated DTOs can stay compatible with existing Skir schemas.
DenseJson::fromJson() and DenseJson::decode() accept both the dense and the readable flavor, like the upstream Skir runtimes.
Readable JSON
use Skir\Runtime\ReadableJson; $json = ReadableJson::toJson($user, [ 'id' => 1, 'name' => 'Jane', ]); // { // "id": 1, // "name": "Jane" // } $data = DenseJson::fromJson($user, $json);
The readable flavor matches upstream toJsonCode(value, "readable"): structs become objects keyed by field name with default-valued fields omitted, constant enum variants become lower-case names, wrapper variants become {"kind": ..., "value": ...}, timestamps become {"unix_millis": ..., "formatted": ...} and bytes become hex: strings. Because field names are part of the output, prefer the dense flavor for anything that is persisted.
ReadableJson::encode() returns the JSON-compatible PHP value. A struct whose fields all hold their default value is returned as an empty stdClass so it still encodes as {}.
Binary format
use Skir\Runtime\BinaryFormat; $bytes = BinaryFormat::encode($user, [ 'id' => 1, 'name' => 'Jane', ]); $data = BinaryFormat::decode($user, $bytes);
The output is byte-for-byte identical to upstream toBytes(), including the leading skir header, and decode() accepts anything upstream fromBytes() accepts.
Current scope
This runtime does not register routes, discover procedures, or make HTTP calls. Those concerns belong in the php-skir/server and php-skir/client packages.