Code blocks
run() evaluates a sequence of expressions in order, against a single
shared context, and returns the value of the last one. Values stored by
an earlier line with set() are visible to later lines.
$engine->run([
'set("greeting", "Hello " + trigger.user.name)',
'greeting.upper()',
], ['trigger' => ['user' => ['name' => 'Ada']]]);
// → "HELLO ADA"
This is the only place the language has anything like a variable.
set() and get()
set(key, value) writes a value into the shared context under key and
returns that value. get(key) reads it back. Both take the key as an
expression, so it's normally a string literal.
$engine->run([
'set("subtotal", trigger.cart.items.map(current.price * current.qty).sum())',
'set("tax", get("subtotal") * 0.15)',
'get("subtotal") + get("tax")',
], $context);
Once a value has been set(), you can also read it as a plain path
(subtotal), not just via get():
$engine->run([
'set("total", trigger.a + trigger.b)',
'total * 2',
], ['trigger' => ['a' => 3, 'b' => 4]]);
// → 14
set() / get() outside run()
set() and get() also work inside a single resolve() or evaluate()
call, sharing context across the placeholders of one template string:
$engine->resolve(
'{{ set("name", "Hello " + trigger.user.name) }}{{ get("name") }}',
['trigger' => ['user' => ['name' => 'Ada']]],
);
// → "Hello AdaHello Ada"
They are always available — they appear in
availableFunctions() alongside
the registered functions.
When to use run()
Reach for run() when a single expression would be unreadable because
the same sub-result is needed several times, or when a calculation has
natural intermediate steps (subtotal → tax → total). For anything that
fits comfortably on one line, a plain evaluate() is simpler.