rekalogika / mapper

An object mapper for PHP and Symfony. Maps an object to another object. Primarily used for transforming an entity to a DTO and vice versa.
MIT License
26 stars 1 forks source link

How put extra argument in construct #219

Closed Norbytus closed 1 week ago

Norbytus commented 2 weeks ago

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

priyadi commented 2 weeks ago

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

Norbytus commented 2 weeks ago

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')]
    ]
]);
priyadi commented 1 week ago

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

Norbytus commented 1 week ago

Thanks