mirror of
https://github.com/danog/Valinor.git
synced 2024-12-11 16:49:51 +01:00
79d7c266ec
When the mapper needs to map a source to a union of objects, it will try to guess which object it will map to, based on the needed arguments of the objects, and the values contained in the source. ```php final class UnionOfObjects { public readonly SomeFooObject|SomeBarObject $object; } final class SomeFooObject { public readonly string $foo; } final class SomeBarObject { public readonly string $bar; } // Will map to an instance of `SomeFooObject` (new \CuyZ\Valinor\MapperBuilder()) ->mapper() ->map(UnionOfObjects::class, ['foo' => 'foo']); // Will map to an instance of `SomeBarObject` (new \CuyZ\Valinor\MapperBuilder()) ->mapper() ->map(UnionOfObjects::class, ['bar' => 'bar']); ```
22 lines
383 B
PHP
22 lines
383 B
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace CuyZ\Valinor\Tests\Integration\Mapping\Fixture;
|
|
|
|
// @PHP8.0 move inside \CuyZ\Valinor\Tests\Integration\Mapping\Object\UnionOfObjectsMappingTest
|
|
final class NativeUnionOfObjects
|
|
{
|
|
public SomeFooObject|SomeBarObject $object;
|
|
}
|
|
|
|
final class SomeFooObject
|
|
{
|
|
public string $foo;
|
|
}
|
|
|
|
final class SomeBarObject
|
|
{
|
|
public string $bar;
|
|
}
|