$converter
->setTemplate('
{% for user in users %}
<user>
<firstname>{{user.firstname}}</firstname>
<lastname>{{user.lastname}}</lastname>
</user>
{% endfor %}
')
->render([
'user' => [
'firstname' => 'John',
'lastname' => 'Snow'
]
]);
You can just typecast it ?
[
'KeyDestination' => 'KeySource'
]
"keyDestination" => "@get(key)"
"keyDestination" => "My name is @get(firstname) @get(lastname)"
"keyDestination" => "My name is @get(payload[0].user.firstname)"
"keyDestination" => '@forEach(keyToAnIterate, "Hello @get(firstname) @get(lastname)" )'
"keyDestination" => '@compute(10 * @get(data.a) / @get(data.b))'
TODO
"keyDestination" => '@compute(10 * @get(data.a) / @get(data.b))'
You can define your own custom command:
"keyDestination" => '@customCommand(param1, param2)'
"keyDestination" => function ($data){
// Do your magic...
return $result;
}
class CustomTransformer extends Transformer{
public function apply(){
// Access data to convert with $this->data
// Access converter data: $this->result
return 'my result';
}
}
$converter = new Converter([
'payload' => [
0 => [
'user' => [
'firsname' => 'Torstein',
'lastname' => 'Horgmo'
]
],
1 => [
'user' => [
'firsname' => 'Marcus',
'lastname' => 'Kleveland'
]
]
],
'extra': [
'total': 20,
'page': 1,
'perPage': 10
]
]);
$convert->convert([
'messages' => '@forEach("payload", "Hello {user.firstname} {user.lastname}!")'
'extra.message' => '{extra.page}/@devide(@get("extra.total"), @get("extra.perPage")) ({extra.perPage} page(s))'
]);
// Will results in
[
'messages' => [
'Hello Torstein Horgmo!',
'Hello Marcus Kleveland!'
],
'extra' => [
'message' => '1/2 (2 pages(s))'
]
]
- Blade compiler (source https://github.com/illuminate/view/blob/master/Compilers/BladeCompiler.php)
- Twig https://twig.symfony.com/