Repository navigation
Releases
Releases · nette/schema
Released version 1.4.0
Your schema can now be the documentation of your configuration: give elements a
description, export the schema as JSON Schema, and editors offer completion, explain
each option and underline mistakes right in the config file.
✨ New Features
- JsonSchema::export() – turns a schema into a JSON Schema
document, the format editors read to validate and complete JSON or YAML files. It exports
types, ranges, patterns, required items, enum values and descriptions. A type that exists
only in PHP, such as a class, throwsNotSupportedExceptioninstead of exporting something
the schema would not accept. - description() – attach a human-readable description to any element. It does not affect
validation, and it travels into the JSON Schema export. - Expect::enum() – stop hand-rolling the conversion of backed enums:
Expect::enum(Suit::class)accepts the backing value or the case itself and always gives
you the case. An enum-typed property inExpect::from()maps to it automatically.
Expect::type(Suit::class)keeps meaning plaininstanceof, as for any other class. - Expect::tuple() – a fixed-size list where each position has its own schema:
Expect::tuple([Expect::string(), Expect::int()]).otherItems()describes the rest
elements,extend()appends positions, and when configurations are layered, a later tuple
replaces the earlier one as a whole. - Expect::listOf() with wrap –
Expect::listOf('string', wrap: true)also accepts a single
value and wraps it into a one-item list, so bothemail: foo@example.comand
email: [a@example.com, b@example.com]work. - mergeMode() and mergeWith() – say in the schema how layered configurations combine
instead of relying on the deep merge:Expect::arrayOf('string')->mergeMode(MergeMode::Replace)
takes the later array as a whole, whileOverwriteKeysandAppendKeysmerge by keys. Any
element can get its own combining function, such as
Expect::bool()->mergeWith(fn($value, $base) => $value || $base). A schema without them
merges exactly as before, and the same calls keep working in 2.0. - castTo('?type') –
castTo('?string')keeps anulland casts everything else. A class
or an enum keeps thenulleven without the question mark, so
Expect::string()->nullable()->castTo(DateTime::class)just works. - Kind-specific element classes –
Expect::string()returns aStringType,Expect::int()
aNumberType,Expect::listOf()anArrayType, so your IDE and PHPStan know which options
each element has. They are subclasses ofType, so existing code keeps working.
⚠️ Deprecations
- before() called repeatedly – a second
before()on the same element still replaces the
first one, but raises a notice: in 2.0 the handlers will chain in declaration order. Merge
them into one. - '?int[]' – in 1.x it means an array of nullable items, while 2.0 reads it as a nullable
array, as phpDoc does. The notice names the replacement that keeps the meaning:
Expect::arrayOf(Expect::type('int')->nullable()). - Options that do not fit the element –
min(),max(),pattern(),items()and
mergeDefaults()on a union such asExpect::type('int|string')belong to the variants:
Expect::anyOf(Expect::int()->min(1), Expect::string()->min(1)). Likewisepattern()on a
number or an array,items()on a string or a number andmergeDefaults()on anything but
an array raise a notice.
🐛 Bug Fixes
- A nullable
anyOf()containing a structure or an array givesnullfor anullinput,
wherever thenullsits among the variants. - Smaller fixes:
anyOf()->deprecated()emits its warning,min()andmax()keep the
precision of large integer bounds, and the internal_prevent_mergingmarker no longer
appears in the output of a structure.
Released version 1.3.7
A maintenance release: PHP 8.6 support, a nicer way to write defaults, and a few edge cases that now fail with a clear message instead of a confusing one.
✨ New Features
- PHP 8.6 is supported
- Defaults can be passed as a named argument:
Expect::string(default: 'abc')
🛡️ Robustness
- Mistakes in a schema now report a clear error: an invalid regex pattern, a variadic constructor in
Expect::from(), or a key transformed into something that cannot be a key Expect::from()ignores non-public and static properties- Calling
process()recursively on the sameProcessorinstance works correctly
Released version 1.3.6
A maintenance release: castTo() learns backed enums, plus a few fixes around nullable arrays, deprecated structures and anyOf().
✨ New Features
- castTo() accepts a backed enum:
Expect::string()->castTo(Status::class)turns the value into the enum case, and a value matching no case is a validation error listing the allowed ones
🐛 Bug Fixes
nullfor anullable()array staysnullinstead of turning into[]- A deprecated nested structure warns only when it is actually present in the input
- Dynamic parameters inside
anyOf()are validated by DI again, andskipDefaultsis honored there
🛡️ Robustness
- A cast to a class that cannot be constructed reports which class it was
- Items with invalid keys no longer overwrite each other, unknown
%placeholders%in messages stay intact, andgetWarnings()works before the firstprocess()
Released version 1.3.5
A code quality release that tightens static analysis and cleans up internals.
- Fixed all PHPStan errors and improved phpDoc annotations
- Switched to singleline
declarestatements across the codebase
Released version 1.3.3
- support for PHP 8.5
- optimized global function calls
Released version 1.3.2
Released version 1.3.0
- requires PHP 8.1
- uses PHP 8.1 features
Released version 1.2.5
Released version 1.2.4
- support for PHP 8.3
- constants are PascalCase