-
-
Notifications
You must be signed in to change notification settings - Fork 76
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: split mapper flexible mode in three distinct modes
The flexible mode has been deprecated in favor of three modes with distinct roles. 1. **The flexible casting** Changes the behaviours explained below: ```php $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' => []] ``` 2. **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. ```php (new \CuyZ\Valinor\MapperBuilder()) ->allowSuperfluousKeys() ->mapper() ->map( 'array{foo: string, bar: int}', [ 'foo' => 'foo', 'bar' => 42, 'baz' => 1337.404, // `baz` will be ignored ] ); ``` 3. **The permissive types** Allows permissive types `mixed` and `object` to be used during mapping. ```php (new \CuyZ\Valinor\MapperBuilder()) ->allowPermissiveTypes() ->mapper() ->map( 'array{foo: string, bar: mixed}', [ 'foo' => 'foo', 'bar' => 42, // Could be any value ] ); ```
- Loading branch information
Showing
19 changed files
with
829 additions
and
294 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.