Oihana PHP Arango

buildWhenLeaf.php

Table of Contents

Functions

buildWhenLeaf()  : string
Compile a single `Field::WHEN` condition leaf into a boolean AQL expression.

Functions

buildWhenLeaf()

Compile a single `Field::WHEN` condition leaf into a boolean AQL expression.

buildWhenLeaf(array<string|int, mixed> $leaf[, string $doc = AQL::DOC ]) : string

A leaf compares a document attribute against a value (or tests its truthiness). Two declaration forms are accepted:

  • Compact list[ '<attr>' ] (truthy), [ '<attr>', <value> ] (equality), [ '<attr>', '<op>', <value> ] (explicit comparator).
  • Associative[ FilterParam::KEY => '<attr>', FilterParam::OP => '<op>', FilterParam::VAL => <value>, FilterParam::ALT => <chain> ]. Without FilterParam::VAL the leaf is a truthiness test.

The compared attribute (left) and the value (right) may be wrapped by an alt chain — same "lower" / { key, val } / { key, val:true } mirror vocabulary as the flat filters (resolved by resolveAltSides()). The value is inlined via aqlValue() (the projection layer carries no bind variables; a WHEN value is developer-declared static configuration, never user input). The attribute is validated by assertAttributeName().

Only the infix comparators (eq, ne, ge, gt, le, lt, in, nin, like, nlike, match, nmatch) are supported; a function-form operator (contains, sw, ew, regex, …) throws — use the flat ?filter= for those.

Parameters
$leaf : array<string|int, mixed>

The condition leaf (compact list or associative form).

$doc : string = AQL::DOC

The document reference (default: AQL::DOC).

Tags
throws
UnsupportedOperationException

If the leaf is empty or uses a non-infix operator.

ValidationException

If the attribute name is unsafe.

since
1.3.0
author

Marc Alcaraz

Return values
string

The boolean AQL expression, e.g. doc.status == 'public' or TO_BOOL(doc.active).

On this page

Search results