edges
Table of Contents
Functions
- assertEdges() : void
- Ensures that a given value is an instance of {@see Edges}.
- buildEdgeCountVariable() : string|null
- Generates a string of multiple AQL 'LET' statements for calculate the number of edges of a specific document.
- buildEdgeVariable() : string
- Builds a single AQL 'LET' subquery string for a specific edge relation.
- buildEdgesVariables() : string
- Generates a string of multiple AQL 'LET' statements for all defined edge variables.
- getEdges() : Edges|null
- Retrieves an {@see Edges} instance from various types of input definitions.
- resolveEdges() : void
- Resolves and initializes internal edge model definitions from a dependency container.
- sortEdgeVariable() : string
- Generates the internal AQL 'SORT' clause for an edge variable subquery.
Functions
assertEdges()
Ensures that a given value is an instance of {@see Edges}.
assertEdges(mixed $value) : void
This helper function acts as a runtime assertion to validate type safety.
If the provided value is not an instance of Edges, an UnexpectedValueException
is thrown with a descriptive message.
This is especially useful when handling dynamically typed data or container-resolved dependencies, where you want to enforce strict model integrity.
Parameters
- $value : mixed
-
The value to assert as an Edges instance.
Tags
buildEdgeCountVariable()
Generates a string of multiple AQL 'LET' statements for calculate the number of edges of a specific document.
buildEdgeCountVariable(string|null $name[, array<string|int, mixed> $definition = [] ][, string $startVertex = AQL::DOC ][, ContainerInterface|null $container = null ]) : string|null
Parameters
- $name : string|null
- $definition : array<string|int, mixed> = []
- $startVertex : string = AQL::DOC
- $container : ContainerInterface|null = null
Tags
Return values
string|nullbuildEdgeVariable()
Builds a single AQL 'LET' subquery string for a specific edge relation.
buildEdgeVariable(string|null $name[, array<string|int, mixed> $definition = [] ][, string $startVertex = AQL::DOC ][, ContainerInterface|null $container = null ][, array<string|int, mixed> $init = [] ]) : string
This method generates a complete traversal subquery, enclosed in parentheses, which is assigned to a 'LET' variable. It handles direction, filtering, sorting, and shaping of the results.
Example output:
LET myFriends = ( FOR v, e IN OUTBOUND 'users/123' friends_edge ... RETURN v.name )
Parameters
- $name : string|null
-
The logical name for this variable (e.g., 'friends', 'comments'). This is used as the AQL 'LET' variable name.
- $definition : array<string|int, mixed> = []
-
Configuration array for the traversal. Expected keys:
AQL::MODEL: (string) The class name of the Edges model.AQL::DIRECTION: (string|null) Traversal direction (OUTBOUND, INBOUND).AQL::UNIQUE: (string|null) Optional AQL variable name, overrides $name.AQL::EDGES: (array) Further edge definitions for nested queries.AQL::JOINS: (array) Join definitions for the target model.AQL::SKIN: (string|null) A 'skin' name to select specific fields.AQL::SORT: (string|array|null) Sort definition (see getSortEdgeVariableExpression).
- $startVertex : string = AQL::DOC
-
The AQL variable name of the starting vertex (default 'doc').
- $container : ContainerInterface|null = null
-
The DI Container reference.
- $init : array<string|int, mixed> = []
-
Optional associative array definitions.
Tags
Return values
string —The complete AQL 'LET' statement.
buildEdgesVariables()
Generates a string of multiple AQL 'LET' statements for all defined edge variables.
buildEdgesVariables([array<string|int, mixed> &$variables = [] ][, array<string|int, mixed> $definitions = [] ][, string $startVertex = AQL::DOC ][, ContainerInterface|null $container = null ][, array<string|int, mixed> $init = [] ]) : string
This is a convenience method that iterates over a list of definitions and calls getEdgeVariable() for each one, concatenating the results.
Parameters
- $variables : array<string|int, mixed> = []
-
The variables list reference to fill.
- $definitions : array<string|int, mixed> = []
-
An associative array of edge definitions [ $name => $definition ].
- $startVertex : string = AQL::DOC
-
The default AQL document reference (start vertex) for all traversals.
- $container : ContainerInterface|null = null
-
The DI Container reference.
- $init : array<string|int, mixed> = []
-
Optional associative array definition.
Tags
Return values
string —A string containing all generated AQL 'LET' statements, or an empty string if none.
getEdges()
Retrieves an {@see Edges} instance from various types of input definitions.
getEdges([array<string|int, mixed>|string|Edges|null $definition = null ][, ContainerInterface|null $container = null ][, string $key = Arango::EDGES ][, Edges|null $default = null ]) : Edges|null
This helper function resolves an Edges object from a direct instance, an array definition,
a service name within a PSR-11 container, or falls back to a provided default value.
Behavior:
- If
$definitionis anEdgesinstance, it is returned as-is. - If
$definitionis an array, the function looks for theArango::EDGESkey. - If
$definitionis a non-empty string and$containercontains a service with that name, the corresponding service is fetched. - If none of the above conditions are met, the
$defaultvalue is returned.
Parameters
- $definition : array<string|int, mixed>|string|Edges|null = null
-
Input definition that may represent an
Edgesinstance, an associative array containing one, or a container service name. - $container : ContainerInterface|null = null
-
Optional PSR-11 container used to resolve string service names.
- $key : string = Arango::EDGES
-
Array key to look for when
$definitionis an array - $default : Edges|null = null
-
Default
Edgesinstance to return if resolution fails.
Tags
Return values
Edges|null —Returns the resolved Edges instance or the default value if not found.
resolveEdges()
Resolves and initializes internal edge model definitions from a dependency container.
resolveEdges([array<string|int, mixed>|null &$edges = [] ][, Container|null $container = null ]) : void
This helper ensures that all edge-related dependencies defined in the model configuration
(under AQL::EDGES) are properly instantiated in the DI container.
It supports multiple edge definition formats:
- Associative arrays mapping a property to its edge configuration.
- Indexed arrays containing simple string references to container entries.
- The special key
AQL::RESOLVE(or__resolve__) for one-shot dependency resolution, used to pre-load edge models in memory without explicit configuration.
Typical usage:
resolveEdges( $model[AQL::EDGES] ?? [], $container );
Behavior:
- Each string identifier found in indexed or
AQL::RESOLVEarrays is resolved through the container. - Associative definitions are analyzed to resolve their
AQL::MODELentry if it refers to a container ID. - Existing
Edgesinstances are left untouched.
Parameters
- $edges : array<string|int, mixed>|null = []
-
The array of edge definitions to resolve (may be associative or indexed).
- $container : Container|null = null
-
The DI container used to resolve
Edgesreferences.
Tags
sortEdgeVariable()
Generates the internal AQL 'SORT' clause for an edge variable subquery.
sortEdgeVariable(array<string|int, mixed>|string|null $definition[, string $vertexRef = AQL::VERTEX ][, string $edgeRef = AQL::EDGE ][, string $defaultProperty = Schema::CREATED ]) : string
This helper method interprets a flexible sort definition and constructs the appropriate AQL 'SORT' expression.
- If $definition is an array: Looks for
AQL::SORT(property) andAQL::ORDER(ASC/DESC) and sorts by the vertex property. - If $definition is a string (legacy): Sorts by that string as the property on the vertex in ASC order.
- If $definition is null (or
AQL::SORTis not set in the array): Sorts by the $defaultProperty (e.g., 'created') on the edge in DESC order.
Parameters
- $definition : array<string|int, mixed>|string|null
-
The sort configuration. Typically the
$definitionarray from getEdgeVariable. - $vertexRef : string = AQL::VERTEX
-
The internal AQL vertex variable reference.
- $edgeRef : string = AQL::EDGE
-
The internal AQL edge variable reference.
- $defaultProperty : string = Schema::CREATED
-
The fallback property to sort by (default: 'created').
Tags
Return values
string —The generated AQL 'SORT' clause (e.g., "SORT v_myVar_collectionName.name ASC").