Skip to content

Allow callable as alternative to custom mapper  #29

@mark-gerarts

Description

@mark-gerarts

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.

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions