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).
- Service:
CleverAge\ProcessBundle\Transformer\CallbackTransformer - Transformer code:
callback
any: whatever the callback accepts.
any: the return value of the callback.
| 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 |
- Simple PHP function (prefer the multibyte
mb_*functions for texts:strtoupper,strtolowerorsubstrwork 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: [',']