Valinor/tests/Unit/Mapper
Nathan Boiron b7a7d22993
feat: introduce a path-mapping source modifier
This modifier can be used to change paths in the source data using a dot
notation.

The mapping is done using an associative array of path mappings. This
array must have the source path as key and the target path as value.

The source path uses the dot notation (eg `A.B.C`) and can contain one
`*` for array paths (eg `A.B.*.C`).

```php
final class Country
{
    /** @var City[] */
    public readonly array $cities;
}

final class City
{
    public readonly string $name;
}

$source = new \CuyZ\Valinor\Mapper\Source\Modifier\PathMapping([
    'towns' => [
        ['label' => 'Ankh Morpork'],
        ['label' => 'Minas Tirith'],
    ],
], [
    'towns' => 'cities',
    'towns.*.label' => 'name',
]);

// After modification this is what the source will look like:
[
    'cities' => [
        ['name' => 'Ankh Morpork'],
        ['name' => 'Minas Tirith'],
    ],
];

(new \CuyZ\Valinor\MapperBuilder())
    ->mapper()
    ->map(Country::class, $source);
```
2022-02-26 11:33:50 +01:00
..
Object feat: introduce automatic named constructor resolution 2022-01-25 18:32:28 +01:00
Source feat: introduce a path-mapping source modifier 2022-02-26 11:33:50 +01:00
Tree feat!: improve interface inferring API 2022-02-24 10:48:49 +01:00
MappingErrorTest.php test: improve FakeType and introduce FakeNode 2022-01-06 14:11:42 +01:00
TreeMapperContainerTest.php feat!: allow mapping to any type 2022-01-02 00:48:01 +01:00