Oihana PHP Arango

buildWhenCondition.php

Table of Contents

Functions

buildWhenCondition()  : string
Compile a `Field::WHEN` descriptor into a boolean AQL expression.

Functions

buildWhenCondition()

Compile a `Field::WHEN` descriptor into a boolean AQL expression.

buildWhenCondition(mixed $when[, string $doc = AQL::DOC ]) : string

Mirrors the recursive grammar of the flat ?filter= DSL (HasFilterConditions) — so a condition written for a filter reads the same here — but compiles inline (no bind variables), because the projection layer (aqlFields()) carries none.

Disambiguation:

  • string → a truthiness leaf: 'active'TO_BOOL(doc.active).
  • associative array → an explicit leaf (see buildWhenLeaf()).
  • list whose first element is a logic keyword (and / or / not) → a group over the remaining conditions; not expects exactly one condition.
  • list whose elements are all arrays → an implicit AND group.
  • list of scalars → a single leaf [ '<attr>', '<op>'?, <value> ].

Examples:

buildWhenCondition( 'active' );
// TO_BOOL(doc.active)

buildWhenCondition( [ 'visibility', 'public' ] );
// doc.visibility == 'public'

buildWhenCondition( [ [ 'a', 'x' ], [ 'b', 'gt', 0 ] ] );
// (doc.a == 'x' && doc.b > 0)

buildWhenCondition( [ 'or', [ 'role', 'admin' ], [ 'owner', 'eq', true ] ] );
// (doc.role == 'admin' || doc.owner == true)

buildWhenCondition( [ 'not', [ 'anonymized', true ] ] );
// !(doc.anonymized == true)
Parameters
$when : mixed

The condition descriptor (string, leaf, or group).

$doc : string = AQL::DOC

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

Tags
throws
UnsupportedOperationException

If the descriptor is malformed (empty, or a not group with the wrong arity).

ValidationException

If a leaf attribute name is unsafe.

since
1.3.0
author

Marc Alcaraz

Return values
string

The boolean AQL expression.

On this page

Search results