mark-gerarts / automapper-plus

An AutoMapper for PHP
MIT License
551 stars 30 forks source link

Pass mapper to a custom constructor callable #24

Closed BoShurik closed 6 years ago

BoShurik commented 6 years ago
$config
    ->registerMapping(Entity::class, DTO::class)
    ->reverseMap()
    ->beConstructedUsing(function (DTO $model, AutoMapperInterface $mapper) {
        $object = new Entity(
            $mapper->map($model->foo, Foo::class)
        );

         return $object;
    })
;

Second argument AutoMapperInterface $mapper can be omitted, so no BC brake here

mark-gerarts commented 6 years ago

Simple & useful, consider it merged! Thanks @BoShurik