Oihana PHP Arango

join.php

Table of Contents

Functions

join()  : AqlQuery
Joins a list of AQL fragments into a single {@see AqlQuery}, with bind collision handling.

Functions

join()

Joins a list of AQL fragments into a single {@see AqlQuery}, with bind collision handling.

join(array<int, mixed> $fragments[, string $separator = ' ' ]) : AqlQuery

Each entry of $fragments is interpreted the same way the aql() helper interprets a value passed in its variadic tail:

  • AqlQuery — query string interpolated as-is, bind variables merged into the resulting AqlQuery (with per-fragment renaming on collision — see below).
  • AqlLiteral — value inlined verbatim into the query string, no bind.
  • Anything else — bound as a value parameter (@jN).

Bind name collisions across fragments are resolved by prefixing the offending names with j{index}_ — the references inside the offending fragment's query string are rewritten to match. The reserved single-@ vs double-@@ syntax used to distinguish value binds from collection binds is preserved.

Empty input returns an empty AqlQuery; a single-entry input goes through the same machinery so the caller can rely on the bind map being well-formed regardless of $fragments length.

Example — assembling N optional FILTER conditions:

$filters = [] ;

if ( $onlyAdmins )  { $filters[] = aql( 'FILTER u.role == ?'   , 'admin' ) ; }
if ( $onlyActive )  { $filters[] = aql( 'FILTER u.active == ?' , true    ) ; }

$query = aql
(
    'FOR u IN users ? RETURN u' ,
    new AqlLiteral( join( $filters )->query ) ,
) ;
// (Or, more directly, assemble through Database::query() with a manually
//  built AqlQuery merging the joined fragment + the rest.)

The separator defaults to a single space (mirroring arangojs aql.join); pass an explicit value to interleave keywords (' AND ', ', ', …).

Parameters
$fragments : array<int, mixed>

Fragments to join.

$separator : string = ' '

Separator interpolated between consecutive fragments (verbatim — like an AqlLiteral).

Return values
AqlQuery
On this page

Search results