mapper icon indicating copy to clipboard operation
mapper copied to clipboard

How put extra argument in construct

Open Norbytus opened this issue 1 year ago • 2 comments

In https://github.com/mark-gerarts/automapper-plus and https://github.com/jolicode/automapper you could put extract argument in construct? This impl have same function? In doc i see https://rekalogika.dev/mapper/preset but its complatecated understand how add one or more extra arguments

Norbytus avatar Oct 10 '24 16:10 Norbytus

I'm not sure what you have in mind. Can you explain that in the form of a code sample?

priyadi avatar Oct 10 '24 16:10 priyadi

Like this https://automapper.jolicode.com/latest/getting-started/context/?h=const#constructor-arguments

class UserDto {
    public function __construct(private string $name, private \DateTime $createdAt) {}
}

$source = new User();
$source->name = 'Jane';

$target = $autoMapper->map($source, UserDTO::class, [
    'constructor_arguments' => [
        UserDTO::class => ['createdAt' => new \DateTime('2021-01-01')]
    ]
]);

Norbytus avatar Oct 10 '24 16:10 Norbytus

It is done in the linked PR, and in v1.11.0. Documentation: https://rekalogika.dev/mapper/object/extra-target-values

priyadi avatar Oct 13 '24 11:10 priyadi

Thanks

Norbytus avatar Oct 13 '24 12:10 Norbytus