-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: attribute metadata integration and tests
- Loading branch information
Showing
43 changed files
with
984 additions
and
325 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
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
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,49 +1,51 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Backbrain\Automapper\Contract\Attributes; | ||
|
||
use Backbrain\Automapper\Contract\ValueResolverInterface; | ||
use Symfony\Component\ExpressionLanguage\Expression; | ||
|
||
#[\Attribute(\Attribute::TARGET_PROPERTY | \Attribute::IS_REPEATABLE)] | ||
class MapFrom | ||
{ | ||
private string $source; | ||
|
||
private ValueResolverInterface|string $mapFrom; | ||
private Expression|ValueResolverInterface $valueResolverOrExpression; | ||
|
||
/** | ||
* Configure the mapping for a specific member. | ||
* The argument `mapFrom` can be Symfony Expression Language expressions. | ||
* <code> | ||
* // using Symfony Expression Language | ||
* // see https://symfony.com/doc/current/reference/formats/expression_language.html | ||
* use Symfony\Component\ExpressionLanguage\Expression; | ||
* class AccountDTO { | ||
* #[ForMember(ProfileDTO::class, | ||
* mapFrom: 'source.givenName~" "~source.givenName', | ||
* )] | ||
* #[MapFrom(ProfileDTO::class, 'source.givenName~" "~source.givenName')] | ||
* public string $displayName; | ||
* } | ||
* </code> | ||
* Within the expression you can use the following variables: | ||
* - `source`: the source object | ||
* - `context`: the current `Backbrain\Automapper\Contracts\ResolutionContextInterface`. | ||
* | ||
* @param string $source the source member type for which this member configuration is applied | ||
* @param ValueResolverInterface|string $mapFrom it takes a ValueResolverInterface or a valid Symfony EL expression that will be used resolve the member value | ||
* @param string $source the source member type for which this member configuration is applied | ||
* @param ValueResolverInterface|Expression|string $valueResolverOrExpression Can be an instance of ValueResolverInterface or a Symfony EL expression that will be used resolve the member value | ||
*/ | ||
public function __construct(string $source, ValueResolverInterface|string $mapFrom) | ||
public function __construct(string $source, string|Expression|ValueResolverInterface $valueResolverOrExpression) | ||
{ | ||
$this->source = $source; | ||
$this->mapFrom = $mapFrom; | ||
$this->valueResolverOrExpression = is_string($valueResolverOrExpression) ? new Expression($valueResolverOrExpression) : $valueResolverOrExpression; | ||
} | ||
|
||
public function getSource(): string | ||
{ | ||
return $this->source; | ||
} | ||
|
||
public function getMapFrom(): ValueResolverInterface|string | ||
public function getValueResolverOrExpression(): Expression|ValueResolverInterface | ||
{ | ||
return $this->mapFrom; | ||
return $this->valueResolverOrExpression; | ||
} | ||
} |
Oops, something went wrong.