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

Allow callable as alternative to custom mapper #29

Open
mark-gerarts opened this issue Oct 10, 2018 · 0 comments
Open

Allow callable as alternative to custom mapper #29

mark-gerarts opened this issue Oct 10, 2018 · 0 comments

Comments

@mark-gerarts
Copy link
Owner

mark-gerarts commented Oct 10, 2018

It would be nice to be able to map an entire object with a callable/closure, as an alternative to creating a custom mapper. E.g. the following:

$config->registerMapping(SomeClass::class, SomeOther::class)
            ->useCustomMapper(new class extends CustomMapper {
                public function mapToObject($source, $destination)
                {
                     // do stuff
                     return $destination;
                }
            });

Would become something like this:

$config->registerMapping(SomeClass::class, SomeOther::class)
            ->fromCallable(function ($source, $destination) {
                     // do stuff
                     return $destination;
                }});

Optionally the mapper can be passed as the third parameter. On a related note, the CustomMapper could maybe use a MapperAwareInterface as well.

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

No branches or pull requests

1 participant