mark-gerarts / automapper-plus

An AutoMapper for PHP
MIT License
551 stars 30 forks source link

Encode a password during mapping in forMember() #76

Open fd6130 opened 3 years ago

fd6130 commented 3 years ago

To encode a password in symfony, we have to use UserPasswordEncoderInterface to encode the password. It will need to pass the User entity as first parameter for the method encodePassword().

It will be cool if we could do something like

$config->registerMapping(UserDto::class, User::class)
    ->forMember("password", function($source, $destination) use ($passwordEncoder) {
         return $passwordEncoder->encodePassword($destination, $source->password);  
   });
fd6130 commented 3 years ago

I found this https://github.com/mark-gerarts/automapper-plus#adding-context

The $context got the destination i need, but i saw this line in the doc

The context argument is an array that can contain any arbitrary value. Note that this argument isn't part of the AutoMapperInterface yet, since it would break backwards compatibility. It will be added in the next major release.

Is it usable in current version?