mark-gerarts / mark-gerarts/automapper-plus
Allow callable as alternative to custom mapper
Nobody has claimed this yet.
- 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
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- 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