Skip to content

Commit

Permalink
fix: source and context not passed to callable transformer
Browse files Browse the repository at this point in the history
  • Loading branch information
MrMeshok committed Oct 3, 2024
1 parent 9de87a7 commit a8f423f
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 11 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
18 changes: 9 additions & 9 deletions src/Transformer/CallableTransformer.php
Original file line number Diff line number Diff line change
Expand Up @@ -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, []];
Expand All @@ -40,19 +44,15 @@ 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, []];
}

$newInput = new Expr\FuncCall(
new Scalar\String_($this->callable),
[
new Arg($input),
]
$args,
);

return [$newInput, []];
Expand Down
4 changes: 2 additions & 2 deletions tests/Fixtures/MapTo/Bar.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down

0 comments on commit a8f423f

Please sign in to comment.