diff --git a/src/AutoMapper.php b/src/AutoMapper.php index 620039b..793fb63 100644 --- a/src/AutoMapper.php +++ b/src/AutoMapper.php @@ -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); diff --git a/test/AutoMapperTest.php b/test/AutoMapperTest.php index 2c45bcd..a88bcfa 100644 --- a/test/AutoMapperTest.php +++ b/test/AutoMapperTest.php @@ -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());