automapper-plus icon indicating copy to clipboard operation
automapper-plus copied to clipboard

Allow context for map() with CustomMapper

Open pysarenkoa opened this issue 3 years ago • 2 comments

Allow context as third argument CustomMapper->mapToObject($source, $destination, array $context = []). As result it works for mapToObject(), but not for map(). Propose: line https://github.com/mark-gerarts/automapper-plus/blob/master/src/AutoMapper.php#L92

return $this->getCustomMapper($mapping)->map($source, $destinationClass);

replace to

return $this->getCustomMapper($mapping)->map($source, $destinationClass, $context);

pysarenkoa avatar Jul 29 '22 11:07 pysarenkoa

Hi @pysarenkoa, this seems like a very reasonable thing to add. Do you want to open up a PR for this? Otherwise I'll look into adding this myself, let me know.

mark-gerarts avatar Jul 31 '22 11:07 mark-gerarts

Hi @mark-gerarts, thanks for your quick response. It will great if you do this yourself.

pysarenkoa avatar Jul 31 '22 14:07 pysarenkoa

This has been added in release 1.4.0. Keep in mind that the minimum PHP version has been bumped to 7.4 for this release, since 7.3 and below are EOL.

mark-gerarts avatar Aug 04 '22 07:08 mark-gerarts

@mark-gerarts does ther any chance to add the feature to 1.3 ? Since my app are using 7.3 php version.

ahmed-bhs avatar Feb 03 '23 13:02 ahmed-bhs

Hi @ahmed-bhs, I'm not really a fan of maintaining several branches. Is it an option that you depend on a specific commit of the library? If so I suggest you depend on ffdb7827e43035fd956dfac368c096276bf870d9, the commit that introduced this feature - but still before the 7.4 requirement. Something like this in composer:

{
    "repositories": [
        {
            "type": "vcs",
            "url": "https://github.com/mark-gerarts/automapper-plus.git"
        }
    ],
    "require": {
        "mark-gerarts/automapper-plus": "dev-master#ffdb7827e43035fd956dfac368c096276bf870d9"
    }
}

Then, once you're ready to upgrade to 7.4+, you can swap back to the regular branch.

mark-gerarts avatar Feb 11 '23 10:02 mark-gerarts