Skip to content

Commit

Permalink
Merge pull request #31 from BoShurik/context-to-constructor
Browse files Browse the repository at this point in the history
Pass context to constructor
  • Loading branch information
mark-gerarts authored Dec 10, 2018
2 parents fcfe8ef + c8d82da commit 51d9e3a
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/AutoMapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ public function map($source, string $destinationClass, array $context = [])
}

$destinationObject = $mapping->hasCustomConstructor()
? $mapping->getCustomConstructor()($source, $this)
? $mapping->getCustomConstructor()($source, $this, $context)
: new $destinationClass;

return $this->doMap($source, $destinationObject, $mapping, $context);
Expand Down
2 changes: 1 addition & 1 deletion test/AutoMapperTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -418,7 +418,7 @@ public function testItMapsInheritedPublicProperty()
public function testACustomConstructorCallbackCanBeProvided()
{
$this->config->registerMapping(Source::class, Destination::class)
->beConstructedUsing(function (Source $source, AutoMapperInterface $mapper): Destination {
->beConstructedUsing(function (Source $source, AutoMapperInterface $mapper, array $context): Destination {
return new Destination('Set during construct');
})
->forMember('name', Operation::ignore());
Expand Down

0 comments on commit 51d9e3a

Please sign in to comment.