Skip to content

Latest commit

 

History

History
53 lines (39 loc) · 1.39 KB

instantiate_transformer.md

File metadata and controls

53 lines (39 loc) · 1.39 KB

InstantiateTransformer

Create a new instance of the configured class, using the input array values as constructor arguments (\ReflectionClass::newInstanceArgs()).

Transformer reference

  • Service: CleverAge\ProcessBundle\Transformer\Object\InstantiateTransformer
  • Transformer code: instantiate

Accepted inputs

array: the constructor arguments. A list is passed positionally; string keys are used as named arguments. Any other value, null included, throws an UnexpectedValueException.

Possible outputs

object: a new instance of the configured class

Options

Code Type Required Default Description
class string X Fully qualified class name to instantiate, must exist (checked with the configuration)

Examples

  • Build an App\Dto\Price object 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'