-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #25 from nikophil/feat/custom-transformer-multi-fi…
…elds feat: pass full input object to property custom transformers
- Loading branch information
Showing
28 changed files
with
371 additions
and
134 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
- [Quick start](/) | ||
- [Symfony](/symfony) | ||
- [Contributing](/contributing) | ||
- [Contributing](/contributing) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace AutoMapper\Extractor; | ||
|
||
use AutoMapper\Transformer\CustomTransformer\CustomModelTransformerInterface; | ||
use AutoMapper\Transformer\CustomTransformer\CustomTransformerInterface; | ||
use PhpParser\Node\Arg; | ||
use PhpParser\Node\Expr; | ||
|
||
final readonly class CustomTransformerExtractor | ||
{ | ||
public function __construct( | ||
private ClassMethodToCallbackExtractor $extractor | ||
) { | ||
} | ||
|
||
/** | ||
* @param class-string<CustomTransformerInterface> $customTransformerClass | ||
*/ | ||
public function extract(string $customTransformerClass, Expr|null $propertyToTransform, Expr $sourceObject): Expr | ||
{ | ||
if (!$propertyToTransform && is_a($customTransformerClass, CustomModelTransformerInterface::class, allow_string: true)) { | ||
throw new \LogicException('CustomModelTransformerInterface must use $propertyToTransform.'); | ||
} | ||
|
||
$arg = is_a($customTransformerClass, CustomModelTransformerInterface::class, allow_string: true) | ||
? $propertyToTransform | ||
// let's pass the full object when using "property" custom transform for more flexibility | ||
: $sourceObject; | ||
|
||
return $this->extractor->extract( | ||
$customTransformerClass, | ||
'transform', | ||
[new Arg($arg)] | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.