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:
-
Single function: "lower" → LOWER(expr)
-
Function with params (simplified): ["substring", 0, 3] → SUBSTRING(expr, 0, 3)
-
Function chain: ["trim","lower"] → LOWER(TRIM(expr))
-
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
Return values
string —The transformed expression.