Skip to content

Latest commit

 

History

History
67 lines (52 loc) · 1.76 KB

File metadata and controls

67 lines (52 loc) · 1.76 KB

ArrayMapTransformer

Apply a chain of transformers to each element of an iterable value. Keys are preserved.

Transformer reference

  • Service: CleverAge\ProcessBundle\Transformer\Array\ArrayMapTransformer
  • Transformer code: array_map

Accepted inputs

array or \Traversable. Any other value throws an \UnexpectedValueException.

Possible outputs

array: the transformed elements, with their original keys

Options

Code Type Required Default Description
transformers array X Transformers applied to each element, see TransformerTrait
skip_null bool false If true, elements whose transformed value is null are removed from the result

When a sub-transformer fails, the thrown TransformerException references the key of the failing element.

Examples

  • Cast each element to string, then uppercase it
# Transformer mapping level
array_map:
  code:
    - '[id]'
    - '[firstname]'
    - '[lastname]'
  transformers:
    array_map:
      transformers:
        cast:
          type: 'string'
        callback:
          callback: strtoupper
  • Convert each stdClass item into an array and remap it
# Transformer options level
array_map:
  transformers:
    cast:
      type: 'array'
    mapping:
      mapping:
        isoCode:
          code: '[sISOCode]'
        name:
          code: '[sName]'