Skip to content

0.7.0

Compare
Choose a tag to compare
@romm romm released this 24 Mar 13:41
· 365 commits to master since this release

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 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.

Full list of changes

⚠ BREAKING CHANGES

  • Change Attributes::ofType return type to array (1a599b)
  • Introduce method to register constructors used during mapping (ecafba)

Features

  • Introduce a path-mapping source modifier (b7a7d2)
  • Introduce a source builder (ad5103)

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)

Other

  • Add Striker HTML report when running infection (79c7a4)
  • Handle class name in function definition (e2451d)
  • Introduce functions container to wrap definition handling (fd1117)