nette/schema
Nette Schema is a lightweight PHP library for validating and normalizing structured data. Define schemas to check arrays and objects, coerce values, and generate clear error messages for configs, APIs, and form input.
A round of fixes to the corners of the validation pipeline that only bite once your schema gets interesting: nullable arrays, invalid keys, deprecated items and anyOf() branches. On top of that, castTo() now speaks backed enums.
Expect::string()->castTo(Status::class) converts the value via Status::from() and, when it doesn't match, reports a proper validation error listing all allowed cases instead of blowing up with a ValueError. Pure (non-backed) enums are rejected up front with a clear message.Error – you get an InvalidStateException naming the target class, so you know what failed to be constructed.null value for a nullable array is finally left as null. Previously the "NEON can't tell null from an empty array" workaround kicked in even for schemas explicitly declared nullable(), silently turning your null into [].'' entry, quietly overwriting each other's values.deprecated() on a required structure no longer emits a warning when the item isn't present in the input at all – you only get warned about deprecated items you actually used.skipDefaults is now honored inside the branch. A DynamicParameter schema also no longer registers itself for deferred validation.%placeholders% intact instead of tripping over an undefined index.A code quality release that tightens static analysis and cleans up internals.
declare statements across the codebaseimproved phpDoc
Structure::extend() #66Structure::getShape() #35Expect::array(shape) returns StructureStructure::merge() without otherItems it merges by overwritingtransform() #52castTo() allows you to create objects #44 #47 #58 #46Structure::skipDefaults() allow to skip defaults per structureAnyOf() must not be emptyAnyOf::firstIsDefault()Expert::arrayOf($stringType, $keyType)normalize() on items #25 #18For the details you can have a look at the diff.
from() supports union typesFor the details you can have a look at the diff.
required() accepts state parameter (#16)For the details you can have a look at the diff.
normalize() #9pattern() (#6)For the details you can have a look at the diff.
Handy library for validating data structures against a given Schema is here! :-)
How can I help you explore Laravel packages today?