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()). A WHEN value is a developer-declared static literal, inlined via aqlValue(), and the attribute is validated by assertAttributeName().

Either side may instead be an AqlBindReference (built with aqlBindRef()): it renders as its @name token — never inlined, never prefixed with the document reference — and its value is supplied at query time through the top-level bind mechanism (AQL::BINDS). This is what lets Field::WHERE compare an array element against a runtime bind (e.g. item.region IN @allowedRegions).

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