Dynamic Cheat Sheet
Mental Model
Structureis runtime state:{ data: array, schema: Schema }- Shape is always defined by
Schema(useSchemaBuilder/SchemaFactory) Structureis immutable (set()/withData()return new instances)
Quick Start
Structure API
Create:Structure::fromSchema(Schema $schema, array $data = []): Structure
schema(): Schemaname(): stringdescription(): stringtoSchema(): Schemadata(): arraytoArray(): arraytoJsonSchema(): arrayhas(string $name): boolget(string $name): mixed
isset($structure->field)is true only when runtime data contains a non-null value or the schema provides a non-null default
withData(array $data): Structureset(string $name, mixed $value): Structureclone(): StructurefromArray(array $data): static
validate(): ValidationResultnormalizeRecord(array $values): arraytransform(): mixedwithValidation(callable $validator): Structure— compatibility no-op, returns a clone
StructureFactory API
fromCallable(callable $callable, ?string $name = null, ?string $description = null): StructurefromFunctionName(string $function, ?string $name = null, ?string $description = null): StructurefromMethodName(string $class, string $method, ?string $name = null, ?string $description = null): StructurefromClass(string $class, ?string $name = null, ?string $description = null): StructurefromSchema(string $name, Schema $schema, string $description = ''): StructurefromJsonSchema(array $jsonSchema): StructurefromArrayKeyValues(string $name, array $data, string $description = ''): StructurefromString(string $name, string $typeString, string $description = ''): Structure
fromString() is a convenience shape parser for compact field lists. It supports top-level comma-separated fields, nested type strings like array{name:string}, and field descriptions in trailing parentheses.
Schema Authoring
UseCognesy\Schema for shape definition:
SchemaBuilderfor fluent authoringSchemaFactoryfor type/class driven schemasCallableSchemaFactoryfor function/method signatures