VerticesTrait uses trait:short, trait:short, trait:short
Provides utilities for handling edge vertex references in ArangoDB edge queries.
This trait manages the source ('from') and target ('to') vertex models for edge collections. It allows initializing these references from arrays or PSR-11 containers and provides a convenient method to generate AQL filter expressions for edges based on '_from' and '_to' vertex identifiers.
Features:
- Initialize 'from' and 'to' vertices via arrays or DI containers.
- Generate vertex filter expressions for AQL queries using
prepareVertices(). - Supports custom logical operators (AND/OR) and document variable names.
- Integrates with the
BindTraitto safely bind variables in queries.
Example usage:
class Edges extends Documents {
use VerticesTrait;
}
$edges = new Edges($container, ['collection' => 'user_follows']);
// Initialize vertices
$edges->initializeVertices
([
AQL::FROM => 'users_from',
AQL::TO => 'users_to'
] , $container);
// Prepare filter for AQL query
$filter = $edges->prepareVertices('123', '456');
// → returns a string like "doc._from == @from && doc._to == @to"
Tags
Table of Contents
Properties
- $from : Documents|null
- The source document collection model (vertex where edges originate).
- $to : Documents|null
- The target document collection model (vertex where edges point to).
Methods
- bind() : string
- Bind a value to an AQL query variable.
- bindCollection() : string
- Bind a collection name to an AQL query variable.
- bindView() : string
- Bind the model's declared View name (`AQL::VIEW` block, {@see Search::NAME}) to an AQL query variable — collection bind parameters (`@@view`) are valid for View names as well.
- initializeFrom() : static
- Initialize the 'from' reference.
- initializeTo() : static
- Initialize the 'to' reference.
- initializeVertices() : static
- Initialize the `from` and `to` vertices references.
- prepareVertices() : string|null
- Prepares the vertices "_from=xxx && _to=xxx" filter expression.
- registerFrom() : $this
- Register the `from` Documents signals.
- registerTo() : $this
- Register the `to` Documents signals.
- releaseFrom() : static
- Release the 'from' reference.
- releaseTo() : static
- Release the 'to' reference.
- releaseVertices() : static
- Release the 'from' and 'to' vertices references.
- unregisterFrom() : $this
- Unregister the `from` Documents signals.
- unregisterTo() : $this
- Unregister the `to` Documents signals.
Properties
$from
The source document collection model (vertex where edges originate).
public
Documents|null
$from
= null
$to
The target document collection model (vertex where edges point to).
public
Documents|null
$to
= null
Methods
bind()
Bind a value to an AQL query variable.
public
bind(mixed $value[, array<string|int, mixed> &$binds = [] ][, string|null $to = null ]) : string
Parameters
- $value : mixed
-
The value to bind to the query.
- $binds : array<string|int, mixed> = []
-
Reference to the array of existing bind variables.
- $to : string|null = null
-
Optional name of the bind variable. If null, a unique name is generated.
Tags
Return values
string —The formatted bind variable (including the "@" prefix as needed) for use in the query.
bindCollection()
Bind a collection name to an AQL query variable.
public
bindCollection([array<string|int, mixed> &$binds = [] ][, array<string|int, mixed> $init = [] ]) : string
Prepares a bind variable for a collection name. Uses the collection defined in $init or
falls back to $this->collection if none is provided.
Parameters
- $binds : array<string|int, mixed> = []
-
Reference to the array of existing bind variables. If null, a new array is used.
- $init : array<string|int, mixed> = []
-
Optional initialization array with keys:
- Arango::COLLECTION => the collection name to bind
- Arango::NAME => optional bind variable name
Tags
Return values
string —The formatted bind variable representing the collection.
bindView()
Bind the model's declared View name (`AQL::VIEW` block, {@see Search::NAME}) to an AQL query variable — collection bind parameters (`@@view`) are valid for View names as well.
public
bindView([array<string|int, mixed> &$binds = [] ]) : string
Parameters
- $binds : array<string|int, mixed> = []
-
Reference to the array of existing bind variables.
Tags
Return values
string —The formatted bind variable representing the View.
initializeFrom()
Initialize the 'from' reference.
public
initializeFrom([array<string|int, mixed>|string|Documents|null $init = null ][, ContainerInterface|null $container = null ]) : static
The source document collection (vertex where edges originate).
Parameters
- $init : array<string|int, mixed>|string|Documents|null = null
-
Can be :
- an associative array containing AQL::FROM key,
- a string service identifier (for PSR-11 container),
- a Documents instance,
- or null.
- $container : ContainerInterface|null = null
Tags
Return values
staticinitializeTo()
Initialize the 'to' reference.
public
initializeTo([array<string|int, mixed>|string|Documents|null $init = null ][, ContainerInterface|null $container = null ]) : static
The target document collection (vertex where edges point to).
Parameters
- $init : array<string|int, mixed>|string|Documents|null = null
-
Can be :
- an associative array containing AQL::FROM key,
- a string service identifier (for PSR-11 container),
- a Documents instance,
- or null.
- $container : ContainerInterface|null = null
Tags
Return values
staticinitializeVertices()
Initialize the `from` and `to` vertices references.
public
initializeVertices([array<string|int, mixed> $init = [] ][, ContainerInterface|null $container = null ]) : static
Note: initialize too the purge reference to use in the onDeleteVertex() method.
Parameters
- $init : array<string|int, mixed> = []
- $container : ContainerInterface|null = null
Tags
Return values
staticprepareVertices()
Prepares the vertices "_from=xxx && _to=xxx" filter expression.
public
prepareVertices([string|null $from = null ][, string|null $to = null ][, array<string|int, mixed> &$binds = [] ][, array<string|int, mixed> $init = [] ]) : string|null
Parameters
- $from : string|null = null
- $to : string|null = null
- $binds : array<string|int, mixed> = []
- $init : array<string|int, mixed> = []
-
The option of the method.
- 'operator' : Indicates if the filter of the vertices use a Logic::AND or Logic::OR operator (default Logic::AND)
- 'variableName' : The name of the document in the query (default 'doc') AQL::DOC_REF
Tags
Return values
string|nullregisterFrom()
Register the `from` Documents signals.
public
registerFrom() : $this
Return values
$thisregisterTo()
Register the `to` Documents signals.
public
registerTo() : $this
Return values
$thisreleaseFrom()
Release the 'from' reference.
public
releaseFrom() : static
Return values
staticreleaseTo()
Release the 'to' reference.
public
releaseTo() : static
Return values
staticreleaseVertices()
Release the 'from' and 'to' vertices references.
public
releaseVertices() : static
Return values
staticunregisterFrom()
Unregister the `from` Documents signals.
public
unregisterFrom() : $this
Return values
$thisunregisterTo()
Unregister the `to` Documents signals.
public
unregisterTo() : $this