Skip to main content

Functions reference

Functions are called by name: name(arg, ...). Their result can be chained onto like any value. You can add your own with registerFunction().


Utility functions​

uuid()​

Returns a new random UUID string.

uuid() → "9b1deb4d-3b7d-4bad-9bdd-2b0d7b3dcb6d"

env(key, default = null)​

Reads an environment variable — only if key is listed in env_whitelist. Any other key throws EvaluatorException. With an empty whitelist (the default), env() is disabled entirely.

env("APP_ENV") → "production" (if whitelisted)
env("MISSING", "fallback") → "fallback"

random(min = 0, max = PHP_INT_MAX)​

A cryptographically secure random integer in [min, max].

random(1, 6) → 4

range(start, end, step = 1)​

An array of numbers from start to end.

range(1, 5) → [1, 2, 3, 4, 5]
range(0, 10, 5) → [0, 5, 10]

coalesce(...values)​

The first argument that is not null, or null if all are.

coalesce(trigger.nickname, trigger.name, "friend")

Type functions​

Casts and guards that work on any value. Each takes the value as its argument: isset(trigger.name), not trigger.name.isset().

FunctionResult
string(value)Cast to string
int(value)Cast to integer
float(value)Cast to float
bool(value)Cast to boolean
json(value)JSON-encode (false if encoding fails)
decode(value)JSON-decode a string to an array
isset(value)true if the value is not null
empty(value)true if the value is empty ("", 0, [], null, false)
not(value)Logical negation
if(condition, then = true, else = false)then if condition is truthy, else else
if(trigger.order.total > 100, "priority", "standard")
string(trigger.order.id)
json(trigger.order.lines)

if() evaluates both then and else before it runs. When a branch must stay lazy (e.g. it would error unless the condition holds), use the ternary operator cond ? a : b instead.


Date functions​

now(), today(), and date() return a chainable date object when called with no format, or a formatted string when passed a format. See Working with dates and the date methods.

now(format = null)​

The current date and time.

now().addDays(5).format("Y-m-d")
now("Y-m-d H:i") → "2026-08-31 14:03"

today(format = null)​

The current date at midnight (start of day).

today().addWeeks(1)

date(value, format = null)​

Parses value as a date. An unparseable value throws EvaluatorException.

date("2026-01-01").addMonths(3).format("Y-m-d") → "2026-04-01"
date(trigger.order.createdAt).isBefore(now())

time(value, format = null)​

An alias of date() — identical behaviour.

timestamp()​

The current Unix timestamp as an integer.


Math functions​

FunctionResult
min(...values)Smallest — flattens array arguments
max(...values)Largest — flattens array arguments
round(value, places = 0)Rounded value
floor(value)Rounded down to an integer
ceil(value)Rounded up to an integer
abs(value)Absolute value
pow(base, exp)base ** exp
sqrt(value)Square root — throws EvaluatorException for a negative value
min(trigger.a, trigger.b, 10)
max(trigger.scores) → largest element of the array
round(trigger.total, 2)

Context functions​

set(key, value) / get(key)​

set() writes value into the shared context under key and returns it; get() reads it back. Most useful inside run(), but also valid within a single resolve() / evaluate() call.

set("tax", trigger.subtotal * 0.15)
get("tax")

Both are always available and always appear in availableFunctions().