Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Encode a password during mapping in forMember() #76

Open
fd6130 opened this issue Mar 13, 2021 · 1 comment
Open

Encode a password during mapping in forMember() #76

fd6130 opened this issue Mar 13, 2021 · 1 comment

Comments

@fd6130
Copy link

fd6130 commented Mar 13, 2021

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
Copy link
Author

fd6130 commented Mar 13, 2021

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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant