Oihana PHP Arango

aqlFieldWrap.php

Table of Contents

Functions

aqlFieldWrap()  : string
Generates an AQL key/value expression that wraps the **current reference** itself under a named key.

Functions

aqlFieldWrap()

Generates an AQL key/value expression that wraps the **current reference** itself under a named key.

aqlFieldWrap(string $key, string $ref, array<string|int, mixed> $options[, ContainerInterface|null $container = null ][, array<string|int, mixed> $init = [] ]) : string

Unlike aqlFieldDocument() — which nests a sub-attribute of the reference (ref.key.subfield) — this helper projects the sub-fields directly against $ref (ref.subfield), so the whole reference is embedded inside a new object under $key. It is the symmetric counterpart of Field::SCOPE : inside an edge traversal it lets a definition hoist the traversal vertex (the related entity) under a named key — e.g. subject — alongside the edge metadata, instead of flattening the vertex fields at the root.

  • With Field::FIELDS : projects the listed sub-fields against $ref and wraps them in a { ... } object under $key.
  • Without Field::FIELDS : a field whitelist is required by default. Pass Field::RAW => true to deliberately embed the whole reference as-is (key: ref) — every attribute of the vertex/edge, no projection.

The wrapped reference may also carry its own relations. The sub-fields can include the usual relation markers (Filter::EDGE / Filter::EDGES / Filter::EDGES_COUNT for edges, Filter::JOIN / Filter::JOINS for joins) and the field declares a companion Field::EDGES / Field::JOINS map of sub-relations that start from the wrapped vertex — exactly the same shape as a top-level projection (fields markers beside an edges/joins registry). The backing LET variables are emitted upstream by buildVariables() with $ref as the traversal root, so the related entities nest inside the wrapped object (e.g. subject.worksFor) in a single query. Field::RAW is mutually exclusive with Field::EDGES / Field::JOINS (a verbatim reference has no projected object to nest into).

Example usage:

// Wrap the traversal vertex under "subject", with a projection
aqlFieldWrap( 'subject', 'v',
[
    Field::FIELDS =>
    [
        'id'        => Filter::DEFAULT ,
        'givenName' => Filter::DEFAULT ,
    ]
]);
// Produces: "subject: { id: v.id, givenName: v.givenName }"

// Wrap the vertex AND nest one of its relations under the wrapped key.
// The sub-edge declares the cardinality marker in Field::FIELDS and the
// traversal definition in Field::EDGES (here reached INBOUND).
aqlFieldWrap( 'subject', 'v',
[
    Field::FIELDS =>
    [
        'id'       => Filter::DEFAULT ,
        'name'     => Filter::DEFAULT ,
        'worksFor' => [ Field::FILTER => Filter::EDGE , Field::UNIQUE => 'worksFor_e1' ] ,
    ] ,
    Field::EDGES =>
    [
        'worksFor' => [ AQL::MODEL => OrgHasMember::class , AQL::DIRECTION => Traversal::INBOUND ] ,
    ] ,
]);
// Produces (the worksFor_e1 LET being emitted upstream against `v`):
// "subject: { id: v.id, name: v.name, worksFor: (IS_OBJECT(worksFor_e1) ? … ) }"

// Wrap the whole vertex as-is (opt-in)
aqlFieldWrap( 'subject', 'v', [ Field::RAW => true ] );
// Produces: "subject: v"
Parameters
$key : string

The output key under which the reference is wrapped.

$ref : string

The reference to wrap (the traversal vertex v by default, or the edge e when the field declares Field::SCOPE => Scope::EDGE).

$options : array<string|int, mixed>

Field options, typically including:

  • Field::FIELDS => array of sub-fields projected against $ref (may include relation markers)
  • Field::EDGES => array of sub-traversal definitions starting from $ref, nested under $key
  • Field::JOINS => array of sub-join definitions resolved from $ref, nested under $key
  • Field::RAW => bool, embed the whole reference when no sub-fields are given (excludes Field::EDGES / Field::JOINS)
$container : ContainerInterface|null = null

The optional DI Container reference.

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

Optional associative array definition.

Tags
throws
ContainerExceptionInterface
NotFoundExceptionInterface
UnsupportedOperationException

If neither Field::FIELDS nor Field::RAW => true is provided, or if Field::RAW => true is combined with Field::EDGES / Field::JOINS.

ValidationException
since
1.0.0
author

Marc Alcaraz

Return values
string

AQL key/value expression wrapping the reference.

On this page

Search results