From a8f423fc7eecd152b1f2d9a9ffc22be0c1b50561 Mon Sep 17 00:00:00 2001 From: Ilya Orlov Date: Thu, 3 Oct 2024 16:46:34 +0500 Subject: [PATCH] fix: source and context not passed to callable transformer --- CHANGELOG.md | 1 + src/Transformer/CallableTransformer.php | 18 +++++++++--------- tests/Fixtures/MapTo/Bar.php | 4 ++-- 3 files changed, 12 insertions(+), 11 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 9c433a88..6d123642 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -14,6 +14,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - [GH#184](https://github.com/jolicode/automapper/pull/184) Fix error when mapping from stdClass to constructor with nullable/optional arguments - [GH#185](https://github.com/jolicode/automapper/pull/185) Fix constructor with default parameter array does not work with constructor_arguments context - [GH#187](https://github.com/jolicode/automapper/pull/187) Fix regression after [GH#184](https://github.com/jolicode/automapper/pull/184) +- [GH#192](https://github.com/jolicode/automapper/pull/192) Fix source and context not passed to callable transformer ## [9.1.2] - 2024-09-03 ### Fixed diff --git a/src/Transformer/CallableTransformer.php b/src/Transformer/CallableTransformer.php index 8a2a4d44..b44779b5 100644 --- a/src/Transformer/CallableTransformer.php +++ b/src/Transformer/CallableTransformer.php @@ -24,13 +24,17 @@ public function __construct( public function transform(Expr $input, Expr $target, PropertyMetadata $propertyMapping, UniqueVariableScope $uniqueVariableScope, Expr\Variable $source): array { + $args = [ + new Arg($input), + new Arg($source), + new Arg(new Expr\Variable('context')), + ]; + if ($this->callableIsMethodFromSource) { $newInput = new Expr\MethodCall( $source, $this->callable, - [ - new Arg($input), - ] + $args, ); return [$newInput, []]; @@ -40,9 +44,7 @@ public function transform(Expr $input, Expr $target, PropertyMetadata $propertyM $newInput = new Expr\MethodCall( new Expr\Variable('result'), $this->callable, - [ - new Arg($input), - ] + $args, ); return [$newInput, []]; @@ -50,9 +52,7 @@ public function transform(Expr $input, Expr $target, PropertyMetadata $propertyM $newInput = new Expr\FuncCall( new Scalar\String_($this->callable), - [ - new Arg($input), - ] + $args, ); return [$newInput, []]; diff --git a/tests/Fixtures/MapTo/Bar.php b/tests/Fixtures/MapTo/Bar.php index 9fff2b26..d89d5410 100644 --- a/tests/Fixtures/MapTo/Bar.php +++ b/tests/Fixtures/MapTo/Bar.php @@ -36,12 +36,12 @@ public function getB(): string return $this->b; } - public function transformC(string $c): string + public function transformC(string $c, array $source, array $context): string { return 'transformC_' . $c; } - public static function transformDStatic(string $c): string + public static function transformDStatic(string $c, array $source, array $context): string { return 'transformDStatic_' . $c; }