Changelog 0.7.0 — 24th of March 2022¶
Notable changes¶
Warning This release introduces a major breaking change that must be considered before updating
Constructor registration
The automatic named constructor discovery has been disabled. It is now mandatory to explicitly register custom constructors that can be used by the mapper.
This decision was made because of a security issue reported by @Ocramius and described in advisory advisory GHSA-xhr8-mpwq-2rr2.
As a result, existing code must list all named constructors that were previously
automatically used by the mapper, and registerer them using the
method MapperBuilder::registerConstructor()
.
The method MapperBuilder::bind()
has been deprecated in favor of the method
above that should be used instead.
final class SomeClass
{
public static function namedConstructor(string $foo): self
{
// …
}
}
(new \CuyZ\Valinor\MapperBuilder())
->registerConstructor(
SomeClass::namedConstructor(...),
// …or for PHP < 8.1:
[SomeClass::class, 'namedConstructor'],
)
->mapper()
->map(SomeClass::class, [
// …
]);
See documentation for more information.
Source builder
The Source
class is a new entry point for sources that are not plain array or
iterable. It allows accessing other features like camel-case keys or custom
paths mapping in a convenient way.
It should be used as follows:
$source = \CuyZ\Valinor\Mapper\Source\Source::json($jsonString)
->camelCaseKeys()
->map([
'towns' => 'cities',
'towns.*.label' => 'name',
]);
$result = (new \CuyZ\Valinor\MapperBuilder())
->mapper()
->map(SomeClass::class, $source);
See documentation for more details about its usage.
⚠ BREAKING CHANGES¶
- Change
Attributes::ofType
return type toarray
(1a599b) - Introduce method to register constructors used during mapping (ecafba)
Features¶
Bug Fixes¶
- Handle numeric key with camel case source key modifier (b8a18f)
- Handle parameter default object value compilation (fdef93)
- Handle variadic arguments in callable constructors (b646cc)
- Properly handle alias types for function reflection (e5b515)