-
Notifications
You must be signed in to change notification settings - Fork 8
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 #84 from jolicode/feat/transformer-expression-lang…
…uage-and-provider feat(transformer): allow expression language for transformer, add provider for custom functions
- Loading branch information
Showing
27 changed files
with
461 additions
and
104 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 |
---|---|---|
@@ -0,0 +1,48 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace AutoMapper\Symfony\Attribute; | ||
|
||
use Symfony\Component\DependencyInjection\Attribute\AutoconfigureTag; | ||
|
||
/** | ||
* Service tag to autoconfigure auto mapper expression services. | ||
* | ||
* You can tag a service: | ||
* | ||
* #[AsAutoMapperExpressionService('foo')] | ||
* class SomeFooService | ||
* { | ||
* public function bar(DummyObject $object): string | ||
* { | ||
* // ... | ||
* } | ||
* | ||
* public function isOk(): bool | ||
* { | ||
* // ... | ||
* } | ||
* | ||
* Then you can use the tagged service in the transformer or check property of MapTo / MapFrom attribute | ||
* | ||
* class DummyObject | ||
* { | ||
* #[MapTo('array', transformer: 'service("foo").bar(source)', if: 'service("foo").isOk()')] | ||
* public string $foo; | ||
* } | ||
*/ | ||
#[\Attribute(\Attribute::TARGET_CLASS)] | ||
class AsAutoMapperExpressionService extends AutoconfigureTag | ||
{ | ||
/** | ||
* @param string|null $alias The alias of the service to use it in routing condition expressions | ||
* @param int $priority Defines a priority that allows the routing condition service to override a service with the same alias | ||
*/ | ||
public function __construct( | ||
?string $alias = null, | ||
int $priority = 0, | ||
) { | ||
parent::__construct('automapper.expression_service', ['alias' => $alias, 'priority' => $priority]); | ||
} | ||
} |
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 |
---|---|---|
@@ -0,0 +1,38 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Symfony\Component\DependencyInjection\Loader\Configurator; | ||
|
||
use AutoMapper\Symfony\ExpressionLanguageProvider; | ||
use Symfony\Component\DependencyInjection\ExpressionLanguage; | ||
|
||
return static function (ContainerConfigurator $container) { | ||
$container->services() | ||
->set('automapper.expression_language', ExpressionLanguage::class) | ||
->call('registerProvider', [ | ||
service(ExpressionLanguageProvider::class), | ||
]) | ||
|
||
->set(ExpressionLanguageProvider::class) | ||
->args([ | ||
tagged_locator('automapper.expression_language_function', 'function'), | ||
]) | ||
->tag('automapper.expression_language_provider') | ||
|
||
->set('automapper.expression_language.env', \Closure::class) | ||
->factory([\Closure::class, 'fromCallable']) | ||
->args([ | ||
[service('service_container'), 'getEnv'], | ||
]) | ||
->tag('automapper.expression_language_function', ['function' => 'env']) | ||
|
||
->set('automapper.expression_language.service', \Closure::class) | ||
->public() | ||
->factory([\Closure::class, 'fromCallable']) | ||
->args([ | ||
[tagged_locator('automapper.expression_service', 'alias'), 'get'], | ||
]) | ||
->tag('automapper.expression_language_function', ['function' => 'service']) | ||
; | ||
}; |
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.