0.17.0
Notable changes
The main feature introduced in this release is the split of the flexible mode in three distinct modes:
-
The flexible casting
Changes the behaviours explained below:
$flexibleMapper = (new \CuyZ\Valinor\MapperBuilder()) ->enableFlexibleCasting() ->mapper(); // --- // Scalar types will accept non-strict values; for instance an // integer type will accept any valid numeric value like the // *string* "42". $flexibleMapper->map('int', '42'); // => 42 // --- // List type will accept non-incremental keys. $flexibleMapper->map('list<int>', ['foo' => 42, 'bar' => 1337]); // => [0 => 42, 1 => 1338] // --- // If a value is missing in a source for a node that accepts `null`, // the node will be filled with `null`. $flexibleMapper->map( 'array{foo: string, bar: null|string}', ['foo' => 'foo'] // `bar` is missing ); // => ['foo' => 'foo', 'bar' => null] // --- // Array and list types will convert `null` or missing values to an // empty array. $flexibleMapper->map( 'array{foo: string, bar: array<string>}', ['foo' => 'foo'] // `bar` is missing ); // => ['foo' => 'foo', 'bar' => []]
-
The superfluous keys
Superfluous keys in source arrays will be allowed, preventing errors when a value is not bound to any object property/parameter or shaped array element.
(new \CuyZ\Valinor\MapperBuilder()) ->allowSuperfluousKeys() ->mapper() ->map( 'array{foo: string, bar: int}', [ 'foo' => 'foo', 'bar' => 42, 'baz' => 1337.404, // `baz` will be ignored ] );
-
The permissive types
Allows permissive types
mixed
andobject
to be used during mapping.(new \CuyZ\Valinor\MapperBuilder()) ->allowPermissiveTypes() ->mapper() ->map( 'array{foo: string, bar: mixed}', [ 'foo' => 'foo', 'bar' => 42, // Could be any value ] );
Full list of changes
Features
- Add support for
strict-array
type (d456eb) - Introduce new callback message formatter (93f898)
- Introduce new helper class to list messages (513827)
- Split mapper flexible mode in three distinct modes (549e5f)
Bug Fixes
- Allow missing and null value for array node in flexible mode (034f1c)
- Allow missing value for shaped array nullable node in flexible mode (08fb0e)
- Handle scalar value casting in union types only in flexible mode (752ad9)