Skip to content

Latest commit

 

History

History
60 lines (44 loc) · 2.03 KB

callback_transformer.md

File metadata and controls

60 lines (44 loc) · 2.03 KB

CallbackTransformer

Call a PHP callable (function or static method) with the input value. The value is inserted between configurable left and right parameters: callback(...left_parameters, $value, ...right_parameters).

Transformer reference

  • Service: CleverAge\ProcessBundle\Transformer\CallbackTransformer
  • Transformer code: callback

Accepted inputs

any: whatever the callback accepts.

Possible outputs

any: the return value of the callback.

Options

Code Type Required Default Description
callback string|array X A valid PHP callable (e.g. mb_strtoupper, ['App\MyClass', 'myStaticMethod']), checked with is_callable
left_parameters array [] Parameters passed before the value
right_parameters array [] Parameters passed after the value

Examples

  • Simple PHP function (prefer the multibyte mb_* functions for texts: strtoupper, strtolower or substr work on bytes, and break or leave the non-ASCII characters, e.g. substr('été', 0, 1) gives an invalid "\xC3")
# Transformer options level
callback:
  callback: mb_strtoupper
  • Function with extra parameters: json_decode($value, true)
# Transformer options level
callback:
  callback: json_decode
  right_parameters: [true]
  • Value in second position: explode(',', $value)
# Transformer options level
callback:
  callback: explode
  left_parameters: [',']