Create a new instance of the configured class, using the input array values as constructor arguments
(\ReflectionClass::newInstanceArgs()).
- Service:
CleverAge\ProcessBundle\Transformer\Object\InstantiateTransformer - Transformer code:
instantiate
array: the constructor arguments. A list is passed positionally; string keys are used as named arguments. Any other
value, null included, throws an UnexpectedValueException.
object: a new instance of the configured class
| Code | Type | Required | Default | Description |
|---|---|---|---|---|
class |
string |
X | Fully qualified class name to instantiate, must exist (checked with the configuration) |
- Build an
App\Dto\Priceobject whose constructor is__construct(float $amount, string $currency)
# Transformer mapping level
price:
code:
- '[amount]'
- '[currency]'
transformers:
instantiate:
class: 'App\Dto\Price'- Same, input
{amount: 12.5, currency: 'EUR'}being passed as named arguments
# Transformer options level
instantiate:
class: 'App\Dto\Price'