mark-gerarts / mark-gerarts/automapper-plus

Allow callable as alternative to custom mapper

Open
#29 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

enhancement
Dominant language
PHP
Stars
562
Forks
32
PR merge metrics
No merged PRs in 30d

Description

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:

```php
$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:

```php
$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.

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reading the registerMapping and useCustomMapper APIs, then inspect CustomMapper and the related MapperAwareInterface idea. Define how a callable alternative and optional third mapper parameter should work, and verify that a callable can map the source into the destination as shown.

Written by the indexing model from the issue text.

Assessment

Tech stack
php
Domain
backend
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.