Oihana PHP Arango

alterExpression.php

Table of Contents

Functions

alterExpression()  : string
Apply an `alt` transformation chain to an arbitrary AQL expression.

Functions

alterExpression()

Apply an `alt` transformation chain to an arbitrary AQL expression.

alterExpression(string $expr, mixed $chain[, array<string|int, mixed> $init = [] ]) : string

Side-agnostic core shared by the key (left) and value (right) sides of a comparison: it wraps $expr — whatever it is (a field reference doc.name, a bind placeholder @value, or the loop variable CURRENT) — with the function(s) described by $chain. Used directly by the filter and facet builders (FilterTrait, FacetTrait) and by the inline-condition helpers (buildInlineFilterCondition()), so there is a single implementation.

Supports multiple syntax formats for $chain:

  1. Single function: "lower" → LOWER(expr)

  2. Function with params (simplified): ["substring", 0, 3] → SUBSTRING(expr, 0, 3)

  3. Function chain: ["trim","lower"] → LOWER(TRIM(expr))

  4. Mixed chain: ["trim",["substring",0,3],"lower"] → LOWER(SUBSTRING(TRIM(expr), 0, 3))

A name the catalogue does not carry is refused, not ignored. Every link is checked against FilterFunction before it is applied, and the refusal names the offending code — never a fragment of the query. Who wrote the chain decides which refusal: a request can fix its own URL, so it gets a ValidationException carrying 400; a model declaration cannot be fixed from the wire, so it gets an UnsupportedOperationException, which surfaces as a 500 — the consumer's code is what has to change.

⚠ One position cannot be checked, by construction. In ["trim","lowr","lower"] the second element is read as a parameter of trim — exactly as it is in the legitimate ["trim","-"] ("strip dashes"). The two notations are indistinguishable there, so a name mistyped in that position stays silent: it becomes a parameter and the rest of the chain is dropped. Write such a chain with each link nested — ["trim",["substring",0,3],"lower"] — and every link is checked again.

Parameters
$expr : string

The expression to transform.

$chain : mixed

The transformation chain (string, list of functions, or null for a no-op).

$init : array<string|int, mixed> = []

Filter initialization array (forwarded to FilterFunction for boolean-return checks).

Tags
throws
UnsupportedOperationException

When a declared chain names a function the catalogue does not carry.

ValidationException

When a pluck sub-field name is unsafe, when a request-supplied chain reaches the engine with no binder, or when a request chain names a function the catalogue does not carry.

Exception
example
alterExpression('doc.name', 'lower')                  // "LOWER(doc.name)"
alterExpression('doc.name', ['trim', 'lower'])        // "LOWER(TRIM(doc.name))"
alterExpression('doc.code', [ 'substring', 0, 3 ] )   // "SUBSTRING(doc.code, 0, 3)"
alterExpression('doc.name', 'lowr')                   // throws — "lowr" is not a function
since
1.0.0
author

Marc Alcaraz

Return values
string —

The transformed expression.

On this page

Search results