Download the PHP package flyokai/data-mate without Composer
On this page you can find all versions of the php package flyokai/data-mate. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download flyokai/data-mate
More information about flyokai/data-mate
Files in flyokai/data-mate
Package data-mate
Short Description Data/Dto helpers and base definitions
License MIT
Informations about the package data-mate
flyokai/data-mate
User docs →
AGENTS.mdThe DTO foundation of the Flyokai framework — Solid/Draft/GreyData states, identity, enums, and collections.
data-mate defines the contract every Data Transfer Object in Flyokai obeys. It pairs the safety of constructor-validated immutables (Solid) with the flexibility of dynamic schemas (Draft, GreyData), and it standardises identity (HasId / HasAltId), enum helpers, and item collections so the rest of the framework can treat data uniformly.
It is built on top of cuyz/valinor for type-safe deserialization.
Features
Dtointerface —toArray(),toDbRow(),with(),cloneWith(),fromArgs()- Three data states —
Solid(immutable, validated),Draft(flexible),GreyData(key/value bag) - Reflection-cached
DtoTrait— automatic Valinor mapping with undefined-vs-null tracking - Identity system —
HasId,HasAltId,HasIdDtowith primary + alternative/composite keys - Enum helpers —
StringEnumTrait,IntEnumTrait,LCStringEnumTrait,UCStringEnumTrait - Collections —
ItemJarinterface andJarTraitfor type-safe iterables - Built-in DTOs —
ConfigJar,DdlTable,DdlTableColumn,DdlTableJar - Validation —
Assertions,ValidationException,InvalidEntityfactories
Installation
Quick start
A Solid DTO (strict, immutable)
A Draft / Solid pairing
Identity
The data-state model
| Marker | Mutability | Construction | Use it for |
|---|---|---|---|
Solid |
Immutable, public readonly props |
Constructor, validated | Domain objects, repositories return these |
Draft |
Mutable, flexible | Same DTO class as Solid but relaxed | Input staging, partial updates |
GreyData |
Dynamic key/value | Backed by $data array |
API payloads, third-party blobs |
fromArray() uses Valinor for tolerant deserialisation; cloneWith() goes through the constructor for strict validation.
toArray() skips properties that were never assigned (undefined ≠ explicit null). toDbRow() builds on top of it and JSON-encodes any remaining array values — so ['data' => ['k' => 'v']] becomes ['data' => '{"k":"v"}'].
GreyData
GreyDataTrait implements a path-aware key/value bag for objects whose schema is dynamic:
Enums
LCStringEnumTrait lower-cases input before lookup; UCStringEnumTrait upper-cases.
Collections (ItemJar)
API surface
| Class / Trait | Purpose |
|---|---|
Dto |
Core interface |
DtoTrait |
Reflection-based Valinor implementation |
Solid / Draft / GreyData |
State markers |
HasId / HasAltId / HasIdDto |
Identity |
EnumTrait, StringEnumTrait, IntEnumTrait, LCStringEnumTrait, UCStringEnumTrait |
Enum helpers |
ItemJar, JarTrait |
Type-safe collections |
ConfigJar, DdlTable, DdlTableJar |
Built-in DTOs |
Assertions |
assertNotNull, assertPositiveInt, assertPositiveFloat |
ValidationException, InvalidEntity |
Errors |
dtoMapper(...) |
Cached configured Valinor TreeMapper |
Gotchas
with()is Valinor-flexible (accepts loose types, slower).cloneWith()is constructor-strict (faster).toDbRow()JSON-encodes arrays — be aware when reading rows back.- A constructor parameter that was never supplied is "undefined" and is skipped in
toArray(). An explicitnullis included. GreyDatadoes not track undefined — every key in$datais preserved.__sleep()only serializes constructor params — implement__wakeup()to reinitialize derived state.- Reflection caches are global static and never cleared (intentional, for performance).
- Alt-ID keys are strings; composite keys are arrays of strings, normalised via sorting.
See also
flyokai/db-schema—#[Table]attribute on Solid DTOs becomes the schema source of truthflyokai/search-criteria— declarative filters for repositories built on Solid DTOsflyokai/magento-dto— DTOs for Magento entities
License
MIT