Oihana PHP Arango

Edges extends Documents uses EdgesPurgeTrait, EdgesCountTrait, EdgesDeleteTrait, EdgesExistTrait, EdgesGetTrait, EdgesInsertTrait

Represents a collection of ArangoDB edges connecting vertices.

This model extends Documents and provides additional methods to manage edges between vertices (from and to).

It supports:

  • Automatic initialization of vertex references (from and to).
  • Counting edges based on vertex filters.
  • AQL query generation for counting edges with bind variables.
Tags
author

Marc Alcaraz (eKameleon)

version
1.0.0

Table of Contents

Constants

EDGE_SUFFIX  : string = '_e'
The suffix used for edge fields in queries.
FIELDS  : string = 'fields'
The 'fields' key for initialization arrays.
JOIN_SUFFIX  : string = '_j'
The suffix used for join fields in queries.
UNIQUE_SUFFIX  : string = '_u'
The suffix used for unique fields in queries.

Properties

$arrays  : array<string|int, mixed>
The per-field embedded-array configuration, normalised to `[ field => [ Arango::MODE => ArrayMode::*, Arango::COUNTER => ?string ] ]`.
$fields  : array<string, mixed>
The fields definitions to return in get/list methods.
$purge  : string|null
The purge mode for this edge collection.
$_purge  : string|null

Methods

__construct()  : mixed
Creates a new Edges instance.
__destruct()  : mixed
Invoked when the Edges instance is removed.
arrayContains()  : bool
Checks whether the array `field` of a single document (identified by `owner`) contains `value`.
arrayDefaults()  : array<string, array<string|int, mixed>|int>
Returns the default seed for the declared embedded array fields: each array field defaults to `[]`, and each declared counter to `0`.
arrayInsert()  : object|null
Adds one or several values to the array `field` of a single document.
arrayMove()  : object|null
Moves an existing `value` to the given zero-based `position` inside the array `field`.
arrayPurgeRef()  : array<string|int, object>|int
Removes a `value` from the array `field` of **every** document of the collection that contains it — typically to purge a now-deleted reference.
arrayRemove()  : object|null
Removes one or several values from the array `field` of a single document.
countAnyVertices()  : int
Counts all unique vertices connected in any direction from the given vertex.
countEdges()  : int
Counts the number of edge documents matching the specified vertices.
countInboundVertices()  : int
Counts all unique inbound vertices connected to the given 'to' vertex.
countOutboundVertices()  : int
Counts all unique outbound vertices connected from the given 'from' vertex.
countVertices()  : int
Counts all vertices connected with a specific direction.
deleteEdge()  : array<string|int, mixed>|object|null
Delete an edge document connecting two vertices.
deleteEdgeFrom()  : array<string|int, mixed>|object|null
Delete all edges where the `_from` vertex matches the given identifier.
deleteEdges()  : array<string|int, mixed>|object|null
Delete all edges connected to a specific vertex, either `_from` or `_to`.
deleteEdgeTo()  : array<string|int, mixed>|object|null
Delete all edges where the `_to` vertex matches the given identifier.
diagnose()  : array<string|int, DiffReport>
Compares everything this model declares with the server state, without touching anything — the read-only half of {@see repair()}.
existEdge()  : bool
Checks if an edge exists between the given '_from' and '_to' vertices.
existEdgeFrom()  : bool
Checks if at least one edge exists from the specified 'from' vertex.
existEdgeTo()  : bool
Checks if at least one edge exists to the specified 'to' vertex.
getAnyVertices()  : object|array<string|int, mixed>|null
Retrieves all vertices connected in any direction from the given vertex.
getFirstAnyVertex()  : object|array<string|int, mixed>|null
Retrieves the first vertex connected in any direction from the given vertex.
getFirstInboundVertex()  : object|array<string|int, mixed>|null
Retrieves the first inbound vertex connected to the given 'to' vertex.
getFirstOutboundVertex()  : object|array<string|int, mixed>|null
Retrieves the first outbound vertex connected from the given 'from' vertex.
getInboundVertices()  : object|array<string|int, mixed>|null
Retrieves all inbound vertices connected to the given 'to' vertex.
getOutboundVertices()  : object|array<string|int, mixed>|null
Retrieves all outbound vertices connected from the given 'from' vertex.
getVertices()  : object|array<string|int, mixed>|null
Retrieves all vertices connected with a specific direction.
hasAnyVertex()  : bool
Checks if a specific target vertex is a neighbor in any direction.
hasInboundVertex()  : bool
Checks if a specific target vertex is an inbound neighbor of the start vertex.
hasOutboundVertex()  : bool
Checks if a specific target vertex is an outbound neighbor of the start vertex.
initializeArrays()  : static
Initialize the per-field embedded-array configuration from the `arrays` option.
initializeDocumentsMethods()  : static
Initialize the Documents HTTP methods signals.
initializeFields()  : static
Initialize fields definitions from an associative array.
initializePurge()  : static
Initialize the purge property from an array or string.
insertEdge()  : object|null
Inserts a new edge document connecting two vertices, optionally checking for uniqueness.
prepareQueryFields()  : array<string, array<string|int, mixed>>|null
Prepares query fields based on internal definitions and optional skin filter.
repair()  : array<string|int, DiffReport>
Reconciles the server with everything this model declares — the acting half of {@see diagnose()}:
returnFields()  : string
Generates an AQL document expression or LET statement with the selected fields.
arrayCounter()  : string|null
Returns the configured length-counter attribute of an array field, or null.
arrayMode()  : string
Resolves the {@see ArrayMode} of an array field, honouring an optional per-call `mode` override, then the declared configuration, then defaulting to LIST.
arrayWith()  : string
Builds the `WITH { ... }` object clause: the array field, its optional length counter, and the `modified` timestamp unless `touch` is disabled.
countEdgesQuery()  : string
Generates the count query and fill the binds array reference.
ensureArrayDefaults()  : Closure|null
Builds an `ensure` closure that seeds the declared array fields to `[]` (and their counters to `0`) for any missing key of a document being created, then applies the optional user-supplied `ensure`. Returns the user closure unchanged when no array field is declared (so models without `AQL::ARRAYS` are untouched).
filterFieldsBySkin()  : array<string, mixed>
Filters fields based on an optional skin.
generateUniqueKey()  : string|null
Generates a unique key for special filters like edges, joins, or unique names.
hasVertex()  : bool
Private helper to check for vertex existence in a specific direction.
normalizeFieldDefinition()  : array<string, mixed>
Normalize a field definition into a structured array for queries.
runArrayUpdate()  : object|null
Compiles and executes a single-document array UPDATE (`FOR ... FILTER ... LET ... UPDATE ... RETURN NEW`), emitting the update signals around the write.

Constants

EDGE_SUFFIX

The suffix used for edge fields in queries.

public string EDGE_SUFFIX = '_e'

FIELDS

The 'fields' key for initialization arrays.

public string FIELDS = 'fields'

JOIN_SUFFIX

The suffix used for join fields in queries.

public string JOIN_SUFFIX = '_j'

UNIQUE_SUFFIX

The suffix used for unique fields in queries.

public string UNIQUE_SUFFIX = '_u'

Properties

$arrays

The per-field embedded-array configuration, normalised to `[ field => [ Arango::MODE => ArrayMode::*, Arango::COUNTER => ?string ] ]`.

public array<string|int, mixed> $arrays = []

$fields

The fields definitions to return in get/list methods.

public array<string, mixed> $fields = []

Keys are field names, values are either a Filter constant, a definition array, or null.

Tags
example
$model->fields =>
[
    Schema::ACTIVE                => Filter::BOOL ,
    Schema::WITH_STATUS           => Field::FILTER => Filter::DEFAULT ,
    Schema::ID                    => Filter::ID ,
    Schema::NAME                  => null , // Filter::DEFAULT ,
    Schema::URL                   => Filter::URL ,
    Schema::CREATED               => Filter::DATETIME ,
    Schema::MODIFIED              => [ Field::FILTER => Filter::DATETIME ] ,
    Schema::IMAGE                 => [ Field::FILTER => Filter::EDGE ] ,
    Schema::ALTERNATIVE_HEADLINE  => Filter::TRANSLATE ,
    Schema::ALTERNATE_NAME        => Filter::TRANSLATE ,
    Schema::DESCRIPTION           => Filter::TRANSLATE ,
    Schema::HEADLINE              => Filter::TRANSLATE ,
    Schema::SLOGAN                => Filter::TRANSLATE ,
    Schema::SCOPE_HAS_PERMISSION  => [ Field::FILTER => Filter::BOOL ] ,
    Schema::TOKEN_EXPIRATION      => [ Field::FILTER => Filter::INT  ] ,
    Schema::PERMISSIONS           => [ Field::FILTER => Filter::EDGES , Field::SKINS => [ Skin::FULL ] ]
    Schema::NUM_PERMISSIONS       => Field::FILTER => Filter::EDGES_COUNT
] ;

$purge virtual

The purge mode for this edge collection.

public string|null $purge

One of the constants defined in Purge or null if no purge is configured.

Hooks
public string|null get public set

Methods

__construct()

Creates a new Edges instance.

public __construct(Container $container[, array<string|int, mixed> $init = [] ]) : mixed
Parameters
$container : Container

The DI Container reference.

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

The options of the Edges model.

  • 'alters' - An associative array of transformation rules used to alter or enrich the document properties returned by the model.
  • 'binds' - The bindvars array definitions
  • 'collection' - The name of the ArangoDB Document collection to manage
  • 'database' - The arangoDB database reference
  • 'from' - The source Documents model reference (vertex where edges originate).
  • 'to' - The target Documents model reference (vertex where edges point to)
Tags
throws
ContainerExceptionInterface
NotFoundExceptionInterface
DependencyException
NotFoundException
ReflectionException
example
$edges = new Edges( $container,
[
    'collection' => 'user_follows',
    'from'       => $usersModel,
    'to'         => $usersModel,
]);

__destruct()

Invoked when the Edges instance is removed.

public __destruct() : mixed

arrayContains()

Checks whether the array `field` of a single document (identified by `owner`) contains `value`.

public arrayContains([array{owner?: mixed, field?: string, value?: mixed, key?: string, prefix?: string, debug?: bool} $init = [] ]) : bool

Generated AQL: RETURN LENGTH( FOR doc IN @@collection FILTER doc._key == @key && POSITION(doc.field, @value) RETURN 1 ) > 0

Parameters
$init : array{owner?: mixed, field?: string, value?: mixed, key?: string, prefix?: string, debug?: bool} = []
Tags
throws
ArangoException
BindException
ContainerExceptionInterface
DependencyException
NotFoundException
NotFoundExceptionInterface
ReflectionException
Return values
bool

True if the value is present.

arrayDefaults()

Returns the default seed for the declared embedded array fields: each array field defaults to `[]`, and each declared counter to `0`.

public arrayDefaults() : array<string, array<string|int, mixed>|int>

Used to initialize a freshly created document so that every declared array field is always a real (possibly empty) array — see ensureArrayDefaults().

Return values
array<string, array<string|int, mixed>|int>

e.g. [ 'tracks' => [], 'numberOfTracks' => 0, 'tags' => [] ].

arrayInsert()

Adds one or several values to the array `field` of a single document.

public arrayInsert([array{owner?: mixed, field?: string, value?: mixed, side?: string, mode?: string, key?: string, prefix?: string, touch?: bool, options?: array|object|string|null, debug?: bool} $init = [] ]) : object|null

The uniqueness and sorting are driven by the field's ArrayMode; value may be a scalar or an array (its elements are appended, never nested).

Generated AQL (LIST/SET, side RIGHT): ... UPDATE doc WITH { field: APPEND(doc.field, @value [, true]) [, counter: LENGTH(...)] [, modified: ...] } ...

Parameters
$init : array{owner?: mixed, field?: string, value?: mixed, side?: string, mode?: string, key?: string, prefix?: string, touch?: bool, options?: array|object|string|null, debug?: bool} = []
Tags
throws
ArangoException
BindException
ContainerExceptionInterface
DependencyException
NotFoundException
NotFoundExceptionInterface
ReflectionException
Throwable
Return values
object|null

The updated document, or null if no document matched.

arrayMove()

Moves an existing `value` to the given zero-based `position` inside the array `field`.

public arrayMove([array{owner?: mixed, field?: string, value?: mixed, position?: int, key?: string, prefix?: string, touch?: bool, options?: array|object|string|null, debug?: bool} $init = [] ]) : object|null

Unsupported on a ArrayMode::SORTED_SET field (the sort order overrides any manual position): an UnsupportedOperationException is thrown.

Generated AQL:

LET __rm  = REMOVE_VALUE(doc.field, @value)
LET __arr = APPEND( PUSH( SLICE(__rm, 0, <pos>), @value, true ), SLICE(__rm, <pos>) )
UPDATE doc WITH { field: __arr [, counter: LENGTH(__arr)] [, modified: ...] } ...
Parameters
$init : array{owner?: mixed, field?: string, value?: mixed, position?: int, key?: string, prefix?: string, touch?: bool, options?: array|object|string|null, debug?: bool} = []
Tags
throws
ArangoException
BindException
ContainerExceptionInterface
DependencyException
NotFoundException
NotFoundExceptionInterface
ReflectionException
Throwable
UnsupportedOperationException
Return values
object|null

The updated document, or null if no document matched.

arrayPurgeRef()

Removes a `value` from the array `field` of **every** document of the collection that contains it — typically to purge a now-deleted reference.

public arrayPurgeRef([array{field?: string, value?: mixed, prefix?: string, touch?: bool, count?: bool, options?: array|object|string|null, debug?: bool} $init = [] ]) : array<string|int, object>|int

Generated AQL: FOR doc IN @@collection FILTER POSITION(doc.field, @value) LET __arr = REMOVE_VALUE(doc.field, @value) UPDATE doc WITH { ... } ... RETURN NEW

Parameters
$init : array{field?: string, value?: mixed, prefix?: string, touch?: bool, count?: bool, options?: array|object|string|null, debug?: bool} = []
Tags
throws
ArangoException
BindException
ContainerExceptionInterface
DependencyException
NotFoundException
NotFoundExceptionInterface
ReflectionException
Throwable
Return values
array<string|int, object>|int

The list of modified documents, or their count when count is true.

arrayRemove()

Removes one or several values from the array `field` of a single document.

public arrayRemove([array{owner?: mixed, field?: string, value?: mixed, key?: string, prefix?: string, touch?: bool, options?: array|object|string|null, debug?: bool} $init = [] ]) : object|null

Generated AQL (scalar value): ... UPDATE doc WITH { field: REMOVE_VALUE(doc.field, @value) [, counter: LENGTH(...)] [, modified: ...] } ... (an array value uses REMOVE_VALUES instead).

Parameters
$init : array{owner?: mixed, field?: string, value?: mixed, key?: string, prefix?: string, touch?: bool, options?: array|object|string|null, debug?: bool} = []
Tags
throws
ArangoException
BindException
ContainerExceptionInterface
DependencyException
NotFoundException
NotFoundExceptionInterface
ReflectionException
Throwable
Return values
object|null

The updated document, or null if no document matched.

countAnyVertices()

Counts all unique vertices connected in any direction from the given vertex.

public countAnyVertices([string|null $vertex = null ][, array<string|int, mixed> $init = [] ]) : int

This is a convenience method for countVertices(Traversal::ANY, ...). It counts unique neighbors (vertices), not relations (edges).

Parameters
$vertex : string|null = null

Optional '_key' or '_id' of the vertex to start from.

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

Optional query initialization array (e.g., AQL::GRAPH).

Tags
throws
ArangoException
BindException
ConstantException
ContainerExceptionInterface
DependencyException
NotFoundException
NotFoundExceptionInterface
ReflectionException
Return values
int

The total count of unique connected vertices.

countEdges()

Counts the number of edge documents matching the specified vertices.

public countEdges([string|null $from = null ][, string|null $to = null ][, array<string|int, mixed> $init = [] ]) : int

This counts the relations (edges), not the unique neighbors.

Parameters
$from : string|null = null

Optional '_from' vertex identifier.

$to : string|null = null

Optional '_to' vertex identifier.

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

Optional query options (e.g., AQL::BINDS, operator => Logic::OR).

Tags
throws
ArangoException
BindException
ContainerExceptionInterface
DependencyException
NotFoundException
NotFoundExceptionInterface
ReflectionException
Return values
int

The total count of matching edge documents.

countInboundVertices()

Counts all unique inbound vertices connected to the given 'to' vertex.

public countInboundVertices([string|null $to = null ][, array<string|int, mixed> $init = [] ]) : int

This is a convenience method for countVertices(Traversal::INBOUND, ...). It counts unique neighbors (vertices), not relations (edges).

Parameters
$to : string|null = null

Optional '_key' or '_id' of the vertex to traverse to.

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

Optional query initialization array (e.g., AQL::GRAPH).

Tags
throws
ArangoException
BindException
ConstantException
ContainerExceptionInterface
DependencyException
NotFoundException
NotFoundExceptionInterface
ReflectionException
Return values
int

The total count of unique inbound vertices.

countOutboundVertices()

Counts all unique outbound vertices connected from the given 'from' vertex.

public countOutboundVertices([string|null $from = null ][, array<string|int, mixed> $init = [] ]) : int

This is a convenience method for countVertices(Traversal::OUTBOUND, ...). It counts unique neighbors (vertices), not relations (edges).

Parameters
$from : string|null = null

Optional '_key' or '_id' of the vertex to start from.

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

Optional query initialization array (e.g., AQL::GRAPH).

Tags
throws
ArangoException
BindException
ConstantException
ContainerExceptionInterface
DependencyException
NotFoundException
NotFoundExceptionInterface
ReflectionException
Return values
int

The total count of unique outbound vertices.

countVertices()

Counts all vertices connected with a specific direction.

public countVertices(string $direction[, string|null $vertex = null ][, array{vertexRef?: string, edgeRef?: string|null, pathRef?: string|null, direction?: string, startVertex?: string, graph?: string|null, edgeCollection?: array|string|null, minDepth?: int|null, maxDepth?: int|null, prune?: string|array|null, options?: array|object|string|null, filter?: string|array|null, binds?: array, from?: string|null, to?: string|null, anyRef?: string|null, docRef?: string|null} $init = [] ]) : int

This counts the destination vertex documents.

Parameters
$direction : string

The direction of the relation: Traversal::OUTBOUND, Traversal::INBOUND, or Traversal::ANY.

$vertex : string|null = null

Optional '_key' or '_id' of the vertex to start the relation from.

$init : array{vertexRef?: string, edgeRef?: string|null, pathRef?: string|null, direction?: string, startVertex?: string, graph?: string|null, edgeCollection?: array|string|null, minDepth?: int|null, maxDepth?: int|null, prune?: string|array|null, options?: array|object|string|null, filter?: string|array|null, binds?: array, from?: string|null, to?: string|null, anyRef?: string|null, docRef?: string|null} = []

Optional query initialization and configuration array.

Tags
throws
ArangoException
BindException
ConstantException
ContainerExceptionInterface
DependencyException
NotFoundException
NotFoundExceptionInterface
ReflectionException
Return values
int

The total count of matching vertices.

deleteEdge()

Delete an edge document connecting two vertices.

public deleteEdge([string|null $from = null ][, string|null $to = null ][, array<string|int, mixed> $init = [] ]) : array<string|int, mixed>|object|null

Builds an AQL query to remove the edge between $from and $to. By default, checks for existing edges to enforce uniqueness (throws Error409) unless disabled via AQL::UNIQUE.

Parameters
$from : string|null = null

The _key or full _id of the source vertex. If only a key is given, it will be resolved using $this->from context.

$to : string|null = null

The _key or full _id of the target vertex. If only a key is given, it will be resolved using $this->to context.

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

Optional array for query options:

  • AQL::UNIQUE (bool) : enforce uniqueness check (default true).
  • AQL::OPTIONS (array): additional options for the underlying ArangoDB INSERT operation.
  • AQL::BINDS, AQL::FILTER, AQL::FIRST, and other options accepted by insert().
Tags
throws
ArangoException

On query execution failure.

BindException

On binding failure.

ContainerExceptionInterface

On container-related errors.

DependencyException

On dependency resolution failure.

NotFoundException

On missing dependencies.

NotFoundExceptionInterface

On missing container entries.

ReflectionException

On reflection errors.

UnsupportedOperationException

If operation is not supported.

Return values
array<string|int, mixed>|object|null

The removed edge document, the first removed edge if multiple exist, or null if none.

deleteEdgeFrom()

Delete all edges where the `_from` vertex matches the given identifier.

public deleteEdgeFrom(string $from[, array<string|int, mixed> $init = [] ]) : array<string|int, mixed>|object|null
Parameters
$from : string

Vertex identifier for the _from field.

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

Optional query options (bind variables, filters, etc.).

Tags
throws
ArangoException
BindException
ContainerExceptionInterface
DependencyException
NotFoundException
NotFoundExceptionInterface
ReflectionException
UnsupportedOperationException
Return values
array<string|int, mixed>|object|null

Removed edge(s), or null if none found.

deleteEdges()

Delete all edges connected to a specific vertex, either `_from` or `_to`.

public deleteEdges(string|array<string|int, mixed> $vertex[, array<string|int, mixed> $init = [] ]) : array<string|int, mixed>|object|null

Constructs a dynamic AQL query to remove any edge documents where the given vertex is present in _from or _to.

Parameters
$vertex : string|array<string|int, mixed>

The vertex key(s) or full _id(s) to remove from the edge collection.

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

Optional query options:

  • AQL::CONTEXT (Documents|string|AQL::FROM|AQL::TO) : base context for vertex resolution.
  • AQL::BINDS, AQL::FILTER, AQL::DOC_REF etc.
Tags
throws
InvalidArgumentException

If the vertex ID is invalid or empty.

ArangoException
BindException
ContainerExceptionInterface
DependencyException
NotFoundException
NotFoundExceptionInterface
ReflectionException
UnsupportedOperationException
Return values
array<string|int, mixed>|object|null

List of removed edge documents, or null if none found.

deleteEdgeTo()

Delete all edges where the `_to` vertex matches the given identifier.

public deleteEdgeTo(string $to[, array<string|int, mixed> $init = [] ]) : array<string|int, mixed>|object|null
Parameters
$to : string

Vertex identifier for the _to field.

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

Optional query options (bind variables, filters, etc.).

Tags
throws
ArangoException
BindException
ContainerExceptionInterface
DependencyException
NotFoundException
NotFoundExceptionInterface
ReflectionException
UnsupportedOperationException
Return values
array<string|int, mixed>|object|null

Removed edge(s), or null if none found.

diagnose()

Compares everything this model declares with the server state, without touching anything — the read-only half of {@see repair()}.

public diagnose() : array<string|int, DiffReport>

The returned list carries one DiffReport per declared structure object, in dependency order:

  1. the collection (DiffKind::COLLECTION) — existence and type (2 document / 3 edge);
  2. the declared indexes (DiffKind::INDEXES, only when the model declares AQL::INDEXES) — one aggregated report: missing indexes, definition drifts (immutable → drop + recreate required), server indexes that are no longer declared;
  3. the View (DiffKind::VIEW, only when the model declares an AQL::VIEW block) — the SearchTrait::viewDiff() report with its declaration-coherence checks.

A model without a collection resolves to a single DiffStatus::INVALID report; without a database to a single DiffStatus::UNREACHABLE report.

Tags
throws
ReflectionException

When a declared IndexOptions cannot be serialised.

Return values
array<string|int, DiffReport>

One report per declared structure object.

existEdge()

Checks if an edge exists between the given '_from' and '_to' vertices.

public existEdge([string|null $from = null ][, string|null $to = null ][, array<string|int, mixed> $init = [] ]) : bool
Parameters
$from : string|null = null

Optional 'from' vertex unique key identifier.

$to : string|null = null

Optional 'to' vertex unique key identifier.

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

Optional query options, e.g., bind variables.

Tags
throws
ArangoException
BindException
ContainerExceptionInterface
DependencyException
NotFoundException
NotFoundExceptionInterface
ReflectionException
example
$edges = new Edges($container, ['collection' => 'user_follows']);
$exists = $edges->existEdge('1', '5');
if ($exists) {
    echo "Edge exists between users/1 and posts/5";
}
Return values
bool

True if at least one edge exists, false otherwise.

existEdgeFrom()

Checks if at least one edge exists from the specified 'from' vertex.

public existEdgeFrom(string $from[, array<string|int, mixed> $init = [] ]) : bool
Parameters
$from : string

The 'from' vertex unique key identifier.

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

Optional query options.

Tags
throws
ArangoException
BindException
ContainerExceptionInterface
DependencyException
NotFoundException
NotFoundExceptionInterface
ReflectionException
example
$edges = new Edges($container, ['collection' => 'user_follows']);
$existsFrom = $edges->existEdgeFrom('1');
if ($existsFrom)
{
    echo "There are edges from users/1";
}
Return values
bool

True if at least one edge exists, false otherwise.

existEdgeTo()

Checks if at least one edge exists to the specified 'to' vertex.

public existEdgeTo(string $to[, array<string|int, mixed> $init = [] ]) : bool
Parameters
$to : string

The 'to' vertex unique key identifier.

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

Optional query options.

Tags
throws
ArangoException
BindException
ContainerExceptionInterface
DependencyException
NotFoundException
NotFoundExceptionInterface
ReflectionException
example
$edges = new Edges($container, ['collection' => 'user_follows']);
$existsTo = $edges->existEdgeTo('5');
if ($existsTo)
{
    echo "There are edges to posts/5";
}
Return values
bool

True if at least one edge exists, false otherwise.

getAnyVertices()

Retrieves all vertices connected in any direction from the given vertex.

public getAnyVertices([string|null $vertex = null ][, array<string|int, mixed> $init = [] ]) : object|array<string|int, mixed>|null

This method executes an AQL query to fetch vertices that are connected via incoming or outgoing edges to the specified vertex in the current edge collection. It is a convenience wrapper for getVertices() with the direction set to Traversal::ANY.

Note: By default, this method returns raw data unless an AQL::TARGET model is provided in the $init options.

Parameters
$vertex : string|null = null

Optional '_key' or '_id' of the vertex to start from. If null, defaults to the current $this->from vertex reference.

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

Optional array of query options:

  • AQL::ANY_REF (string) : Context for ANY traversal when using a _key (AQL::FROM or AQL::TO). Defaults to AQL::FROM.
  • AQL::DOC_REF (string) : AQL variable name for the vertex (default: 'vertex').
  • AQL::FIRST (bool) : Return only the first matched vertex.
  • AQL::FROM (Documents) : Override the default _from model instance.
  • AQL::GRAPH (string) : The name of a graph to use for traversal.
  • AQL::LIMIT (int) : Maximum number of vertices to return.
  • AQL::MAX_DEPTH (int) : Maximum traversal depth (requires AQL::GRAPH).
  • AQL::MIN_DEPTH (int) : Minimum traversal depth (requires AQL::GRAPH).
  • AQL::OFFSET (int) : Number of vertices to skip.
  • AQL::PRUNE (string|array) : AQL PRUNE condition for graph traversals (requires AQL::GRAPH).
  • AQL::RAW (bool) : Return raw array data. Defaults to true unless AQL::TARGET is specified.
  • AQL::RETURN (string) : Manually specify the AQL RETURN expression.
  • AQL::SORT (string|array) : Sorting criteria.
  • AQL::TARGET (Documents) : Manually specify a Document model for schema mapping.
  • AQL::TO (Documents) : Override the default _to model instance.
  • Additional bind variables can also be passed.
Tags
throws
ArangoException

If there is an error executing the AQL query.

BindException

If a bind variable is missing or invalid.

ConstantException

If the $direction argument is not a valid Traversal constant.

InvalidArgumentException

If the vertex ID is null or empty after processing.

ContainerExceptionInterface

If the DI container fails.

DependencyException

If a dependency is missing in the container.

NotFoundException

If the DI container cannot find a required service.

NotFoundExceptionInterface

Same as above, PSR-11 interface.

ReflectionException

If schema reflection fails.

Example

// $edges = Edges for 'user_follows_user'
$edges = new Edges($container, ['collection' => 'user_follows_user']);

// Get all followers and all followed users for 'users/1'
$allNeighbors = $edges->getAnyVertices('1');
Return values
object|array<string|int, mixed>|null

Returns an array of vertex documents, a single vertex object if AQL::FIRST is true, or null if no vertices found.

getFirstAnyVertex()

Retrieves the first vertex connected in any direction from the given vertex.

public getFirstAnyVertex([string|null $vertex = null ][, array<string|int, mixed> $init = [] ]) : object|array<string|int, mixed>|null

This is a convenience method that wraps getAnyVertices() with the AQL::FIRST flag set to true, returning only the first vertex found in the ANY traversal of the current edge collection.

It executes an AQL query equivalent to:

FOR v IN ANY @vertex @@collection RETURN v

but only returns the first resulting vertex document (if any).

Parameters
$vertex : string|null = null

Optional '_key' or '_id' of the vertex to start from. If null, defaults to the current $this->from vertex reference.

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

Optional query initialization array, merged with [AQL::FIRST => true].

  • AQL::ANY_REF (string) : Context for ANY traversal when using a _key (AQL::FROM or AQL::TO). Defaults to AQL::FROM.
  • AQL::DOC_REF (string) : AQL variable name for the vertex (default: 'vertex').
  • AQL::FROM (Documents) : Override the default _from model instance.
  • AQL::GRAPH (string) : The name of a graph to use for traversal.
  • AQL::LIMIT (int) : Maximum number of vertices to return.
  • AQL::MAX_DEPTH (int) : Maximum traversal depth (requires AQL::GRAPH).
  • AQL::MIN_DEPTH (int) : Minimum traversal depth (requires AQL::GRAPH).
  • AQL::OFFSET (int) : Number of vertices to skip.
  • AQL::PRUNE (string|array) : AQL PRUNE condition for graph traversals (requires AQL::GRAPH).
  • AQL::RAW (bool) : Return raw array data. Defaults to true unless AQL::TARGET is specified.
  • AQL::RETURN (string) : Manually specify the AQL RETURN expression.
  • AQL::SORT (string|array) : Sorting criteria.
  • AQL::TARGET (Documents) : Manually specify a Document model for schema mapping.
  • AQL::TO (Documents) : Override the default _to model instance.
  • Additional bind variables can also be passed.
Tags
throws
ArangoException

If there is an error executing the AQL query.

BindException

If a bind variable is missing or invalid.

ConstantException

If the $direction argument is not a valid Traversal constant.

InvalidArgumentException

If the vertex ID is null or empty after processing.

ContainerExceptionInterface

If the DI container fails.

DependencyException

If a dependency is missing in the container.

NotFoundException

If the DI container cannot find a required service.

NotFoundExceptionInterface

Same as above, PSR-11 interface.

ReflectionException

If schema reflection fails.

Return values
object|array<string|int, mixed>|null

The first vertex document connected to the given vertex, or null if no edge exists.

getFirstInboundVertex()

Retrieves the first inbound vertex connected to the given 'to' vertex.

public getFirstInboundVertex([string|null $to = null ][, array<string|int, mixed> $init = [] ]) : object|array<string|int, mixed>|null

This is a convenience method that wraps getInboundVertices() with the AQL::FIRST flag set to true, returning only the first vertex found in the inbound traversal of the current edge collection.

It executes an AQL query equivalent to:

FOR v IN INBOUND @to @@collection RETURN v

but only returns the first resulting vertex document (if any).

Parameters
$to : string|null = null

Optional '_key' or '_id' of the vertex to traverse to. If null, defaults to the current $this->to vertex reference.

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

Optional query initialization array, merged with [AQL::FIRST => true].

  • AQL::DOC_REF (string) : AQL variable name for the vertex (default: 'vertex').
  • AQL::FROM (Documents) : Override the default _from model instance.
  • AQL::GRAPH (string) : The name of a graph to use for traversal.
  • AQL::LIMIT (int) : Maximum number of vertices to return.
  • AQL::MAX_DEPTH (int) : Maximum traversal depth (requires AQL::GRAPH).
  • AQL::MIN_DEPTH (int) : Minimum traversal depth (requires AQL::GRAPH).
  • AQL::OFFSET (int) : Number of vertices to skip.
  • AQL::PRUNE (string|array) : AQL PRUNE condition for graph traversals (requires AQL::GRAPH).
  • AQL::RAW (bool) : Return raw array data instead of mapped objects.
  • AQL::RETURN (string) : Manually specify the AQL RETURN expression.
  • AQL::SORT (string|array) : Sorting criteria.
  • AQL::TARGET (Documents) : Manually specify a Document model for schema mapping.
  • AQL::TO (Documents) : Override the default _to model instance.
  • Additional bind variables can also be passed.
Tags
throws
ArangoException

If there is an error executing the AQL query.

BindException

If a bind variable is missing or invalid.

ConstantException

If the $direction argument is not a valid Traversal constant.

InvalidArgumentException

If the vertex ID is null or empty after processing.

ContainerExceptionInterface

If the DI container fails.

DependencyException

If a dependency is missing in the container.

NotFoundException

If the DI container cannot find a required service.

NotFoundExceptionInterface

Same as above, PSR-11 interface.

ReflectionException

If schema reflection fails.

Example

// $edges = Edges for 'user_follows_user'
$edges = new Edges($container, ['collection' => 'user_follows_user']);

// Retrieve the first vertex that follows 'users/1' (their first follower)
$firstFollower = $edges->getFirstInboundVertex('users/1');
Return values
object|array<string|int, mixed>|null

The first inbound vertex document connected to the given vertex, or null if no inbound edge exists.

getFirstOutboundVertex()

Retrieves the first outbound vertex connected from the given 'from' vertex.

public getFirstOutboundVertex([string|null $from = null ][, array<string|int, mixed> $init = [] ]) : object|array<string|int, mixed>|null

This is a convenience method that wraps getOutboundVertices() with the AQL::FIRST flag set to true, returning only the first vertex found in the outbound traversal of the current edge collection.

It executes an AQL query equivalent to:

FOR v IN OUTBOUND @from @@collection RETURN v

but only returns the first resulting vertex document (if any).

Parameters
$from : string|null = null

Optional '_key' or '_id' of the vertex to start from. If null, defaults to the current $this->from vertex reference.

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

Optional query initialization array, merged with [AQL::FIRST => true].

  • AQL::DOC_REF (string) : AQL variable name for the vertex (default: 'vertex').
  • AQL::FROM (Documents) : Override the default _from model instance.
  • AQL::GRAPH (string) : The name of a graph to use for traversal.
  • AQL::LIMIT (int) : Maximum number of vertices to return.
  • AQL::MAX_DEPTH (int) : Maximum traversal depth (requires AQL::GRAPH).
  • AQL::MIN_DEPTH (int) : Minimum traversal depth (requires AQL::GRAPH).
  • AQL::OFFSET (int) : Number of vertices to skip.
  • AQL::PRUNE (string|array) : AQL PRUNE condition for graph traversals (requires AQL::GRAPH).
  • AQL::RAW (bool) : Return raw array data instead of mapped objects.
  • AQL::RETURN (string) : Manually specify the AQL RETURN expression.
  • AQL::SORT (string|array) : Sorting criteria.
  • AQL::TARGET (Documents) : Manually specify a Document model for schema mapping.
  • AQL::TO (Documents) : Override the default _to model instance.
  • Additional bind variables can also be passed.
Tags
throws
ArangoException

If there is an error executing the AQL query.

BindException

If a bind variable is missing or invalid.

ConstantException

If the $direction argument is not a valid Traversal constant.

InvalidArgumentException

If the vertex ID is null or empty after processing.

ContainerExceptionInterface

If the DI container fails.

DependencyException

If a dependency is missing in the container.

NotFoundException

If the DI container cannot find a required service.

NotFoundExceptionInterface

Same as above, PSR-11 interface.

ReflectionException

If schema reflection fails.

Example

$edges = new Edges($container, ['collection' => 'user_follows']);

// Retrieve the first vertex that 'users/1' follows
$firstVertex = $edges->getFirstOutboundVertex('users/1');

if ($firstVertex) {
echo "First followed vertex: " . $firstVertex->_id . PHP_EOL;
}
Return values
object|array<string|int, mixed>|null

The first outbound vertex document connected from the given vertex, or null if no outbound edge exists.

getInboundVertices()

Retrieves all inbound vertices connected to the given 'to' vertex.

public getInboundVertices([string|null $to = null ][, array<string|int, mixed> $init = [] ]) : object|array<string|int, mixed>|null

This method executes an AQL query to fetch vertices that are connected via incoming edges to the specified vertex in the current edge collection. It is a convenience wrapper for getVertices() with the direction set to Traversal::INBOUND.

Parameters
$to : string|null = null

Optional '_key' or '_id' of the vertex to traverse to. If null, defaults to the current $this->to vertex reference.

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

Optional array of query options:

  • AQL::DOC_REF (string) : AQL variable name for the vertex (default: 'vertex').
  • AQL::FIRST (bool) : Return only the first matched vertex.
  • AQL::FROM (Documents) : Override the default _from model instance.
  • AQL::GRAPH (string) : The name of a graph to use for traversal.
  • AQL::LIMIT (int) : Maximum number of vertices to return.
  • AQL::MAX_DEPTH (int) : Maximum traversal depth (requires AQL::GRAPH).
  • AQL::MIN_DEPTH (int) : Minimum traversal depth (requires AQL::GRAPH).
  • AQL::OFFSET (int) : Number of vertices to skip.
  • AQL::PRUNE (string|array) : AQL PRUNE condition for graph traversals (requires AQL::GRAPH).
  • AQL::RAW (bool) : Return raw array data instead of mapped objects.
  • AQL::RETURN (string) : Manually specify the AQL RETURN expression.
  • AQL::SORT (string|array) : Sorting criteria.
  • AQL::TARGET (Documents) : Manually specify a Document model for schema mapping (overrides default $from model).
  • AQL::TO (Documents) : Override the default _to model instance.
  • Additional bind variables can also be passed.
Tags
throws
ArangoException

If there is an error executing the AQL query.

BindException

If a bind variable is missing or invalid.

ConstantException

If the $direction argument is not a valid Traversal constant.

InvalidArgumentException

If the vertex ID is null or empty after processing.

ContainerExceptionInterface

If the DI container fails.

DependencyException

If a dependency is missing in the container.

NotFoundException

If the DI container cannot find a required service.

NotFoundExceptionInterface

Same as above, PSR-11 interface.

ReflectionException

If schema reflection fails.

Example

// $edges = Edges for 'user_follows_user'
$edges = new Edges($container, ['collection' => 'user_follows_user']);

// Get all vertices that follow 'users/1' (all followers)
$followers = $edges->getInboundVertices('1');
Return values
object|array<string|int, mixed>|null

Returns an array of vertex documents, a single vertex object if AQL::FIRST is true, or null if no vertices found.

getOutboundVertices()

Retrieves all outbound vertices connected from the given 'from' vertex.

public getOutboundVertices([string|null $from = null ][, array<string|int, mixed> $init = [] ]) : object|array<string|int, mixed>|null

This method executes an AQL query to fetch vertices that are connected via outgoing edges from the specified vertex in the current edge collection. It is a convenience wrapper for getVertices() with the direction set to Traversal::OUTBOUND.

Parameters
$from : string|null = null

Optional '_key' or '_id' of the vertex to start from. If null, defaults to the current $this->from vertex reference.

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

Optional array of query options:

  • AQL::DOC_REF (string) : AQL variable name for the vertex (default: 'vertex').
  • AQL::FIRST (bool) : Return only the first matched vertex.
  • AQL::FROM (Documents) : Override the default _from model instance.
  • AQL::GRAPH (string) : The name of a graph to use for traversal.
  • AQL::LIMIT (int) : Maximum number of vertices to return.
  • AQL::MAX_DEPTH (int) : Maximum traversal depth (requires AQL::GRAPH).
  • AQL::MIN_DEPTH (int) : Minimum traversal depth (requires AQL::GRAPH).
  • AQL::OFFSET (int) : Number of vertices to skip.
  • AQL::PRUNE (string|array) : AQL PRUNE condition for graph traversals (requires AQL::GRAPH).
  • AQL::RAW (bool) : Return raw array data instead of mapped objects.
  • AQL::RETURN (string) : Manually specify the AQL RETURN expression.
  • AQL::SORT (string|array) : Sorting criteria.
  • AQL::TARGET (Documents) : Manually specify a Document model for schema mapping (overrides default $to model).
  • AQL::TO (Documents) : Override the default _to model instance.
  • Additional bind variables can also be passed.
Tags
throws
ArangoException

If there is an error executing the AQL query.

BindException

If a bind variable is missing or invalid.

ConstantException

If the $direction argument is not a valid Traversal constant.

InvalidArgumentException

If the vertex ID is null or empty after processing.

ContainerExceptionInterface

If the DI container fails.

DependencyException

If a dependency is missing in the container.

NotFoundException

If the DI container cannot find a required service.

NotFoundExceptionInterface

Same as above, PSR-11 interface.

ReflectionException

If schema reflection fails.

Example

$edges = new Edges($container, ['collection' => 'user_follows']);

// Get all outbound vertices from 'users/1'
$vertices = $edges->getOutboundVertices('1');

// Get only the first outbound vertex
$firstVertex = $edges->getOutboundVertices('1', [AQL::FIRST => true]);
Return values
object|array<string|int, mixed>|null

Returns an array of vertex documents, a single vertex object if AQL::FIRST is true, or null if no vertices found.

getVertices()

Retrieves all vertices connected with a specific direction.

public getVertices(string $direction[, string|null $vertex = null ][, array<string|int, mixed> $init = [] ]) : object|array<string|int, mixed>|null

This method executes an AQL query to fetch vertices that are connected via edges from the specified vertex in the current edge collection. It supports standard collection traversal (FOR v IN ... @@collection) and named graph traversal (FOR v IN ... GRAPH 'graph_name').

It can optionally return only the first result, or a set of results as an array.

Parameters
$direction : string

The direction of the relation: Traversal::OUTBOUND, Traversal::INBOUND, or Traversal::ANY.

$vertex : string|null = null

Optional '_key' or '_id' of the vertex to start the relation from. If a full '_id' (e.g., "users/123") is provided, it is used directly (assumes vertexID handles this). If only a '_key' (e.g., "123") is provided, it will be prefixed based on context:

  • OUTBOUND: Uses the $from collection.
  • INBOUND: Uses the $to collection.
  • ANY: Uses the $from collection by default (configurable via AQL::ANY_REF).
$init : array<string|int, mixed> = []

Optional array of query options:

  • AQL::ANY_REF (string) : Context for ANY traversal when using a _key (AQL::FROM or AQL::TO). Defaults to AQL::FROM.
  • AQL::DOC_REF (string) : AQL variable name for the vertex (default: 'vertex').
  • AQL::FIRST (bool) : Return only the first matched vertex.
  • AQL::FROM (Documents) : Override the default _from model instance.
  • AQL::GRAPH (string) : The name of a graph to use for traversal (enables graph-specific options).
  • AQL::LIMIT (int) : Maximum number of vertices to return.
  • AQL::MAX_DEPTH (int) : Maximum traversal depth (requires AQL::GRAPH).
  • AQL::MIN_DEPTH (int) : Minimum traversal depth (requires AQL::GRAPH).
  • AQL::OFFSET (int) : Number of vertices to skip (for pagination).
  • AQL::PRUNE (string|array) : AQL PRUNE condition for graph traversals (requires AQL::GRAPH).
  • AQL::RAW (bool) : Return raw array data. Defaults to true for ANY traversals unless AQL::TARGET is specified.
  • AQL::RETURN (string) : Manually specify the AQL RETURN expression (e.g., "v.name"). Overrides model-defined returnFields.
  • AQL::SORT (string|array) : Sorting criteria (e.g., "vertex.name ASC"). Overrides model-defined prepareSort.
  • AQL::TARGET (Documents) : Manually specify a Document model for schema mapping, especially useful for ANY traversals.
  • AQL::TO (Documents) : Override the default _to model instance.
  • Additional bind variables can also be passed.
Tags
throws
ArangoException

If there is an error executing the AQL query.

BindException

If a bind variable is missing or invalid.

ConstantException

If the $direction argument is not a valid Traversal constant.

InvalidArgumentException

If the vertex ID is null or empty after processing.

ContainerExceptionInterface

If the DI container fails.

DependencyException

If a dependency is missing in the container.

NotFoundException

If the DI container cannot find a required service.

NotFoundExceptionInterface

Same as above, PSR-11 interface.

ReflectionException

If schema reflection fails.

example

Assumes $edges collection connects 'users' ($from) to 'groups' ($to)

$edges = new Edges($container, ['collection' => 'user_joins_group']);

Get all outbound vertices (groups) from 'users/1'

$vertices = $edges->getVertices( Traversal::OUTBOUND , '1' ) ;

Get only the first outbound vertex

$firstVertex = $edges->getVertices( Traversal::OUTBOUND , '1' , [AQL::FIRST => true] ) ;

Get all inbound vertices (users) from 'groups/1'

$vertices = $edges->getVertices( Traversal::INBOUND , '1' ) ;

Get all 'any' vertices from 'users/1' (works with a full _id)

$vertices = $edges->getVertices( Traversal::ANY , 'users/1' ) ;

Get 'any' vertices using _key '1'.

$vertices = $edges->getVertices( Traversal::ANY , '1' ) ;

Note : By default, it assumes '1' is a 'user' (AQL::FROM) -> 'users/1'

Force 'any' traversal to use '1' as a 'group' (AQL::TO) -> 'groups/1'

$vertices = $edges->getVertices
(
    Traversal::ANY ,
    '1' ,
    [ AQL::ANY_REF => AQL::TO ]
);

Get outbound vertices using a named graph 'my_graph'

$vertices = $edges->getVertices
(
    Traversal::OUTBOUND ,
    'users/1' ,
    [ AQL::GRAPH => 'my_graph' ]
);

Get raw outbound vertices sorted by name

$vertices = $edges->getVertices
(
    Traversal::OUTBOUND ,
    'users/1' ,
    [ AQL::RAW => true, AQL::SORT => 'vertex.name ASC' ]
);
see
PrepareTraversalTrait
Return values
object|array<string|int, mixed>|null

Returns an array of vertex documents or a single vertex object if AQL::FIRST is true.

hasAnyVertex()

Checks if a specific target vertex is a neighbor in any direction.

public hasAnyVertex(string $source, string $target[, array<string|int, mixed> $init = [] ]) : bool
Parameters
$source : string

The '_key' or '_id' of the vertex to start from.

$target : string

The '_key' or '_id' of the target vertex to check for.

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

Optional array of query options (e.g., AQL::GRAPH).

Tags
throws
ArangoException
BindException
ContainerExceptionInterface
DependencyException
NotFoundException
NotFoundExceptionInterface
ReflectionException
ConstantException
Return values
bool

True if the target vertex is a neighbor, false otherwise.

hasInboundVertex()

Checks if a specific target vertex is an inbound neighbor of the start vertex.

public hasInboundVertex(string $to, string $from[, array<string|int, mixed> $init = [] ]) : bool
Parameters
$to : string

The '_key' or '_id' of the vertex to traverse to (start vertex).

$from : string

The '_key' or '_id' of the target vertex to check for.

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

Optional array of query options (e.g., AQL::GRAPH).

Tags
throws
ArangoException
BindException
ContainerExceptionInterface
DependencyException
NotFoundException
NotFoundExceptionInterface
ReflectionException
ConstantException
Return values
bool

True if the target vertex is an inbound neighbor, false otherwise.

hasOutboundVertex()

Checks if a specific target vertex is an outbound neighbor of the start vertex.

public hasOutboundVertex(string $from, string $to[, array<string|int, mixed> $init = [] ]) : bool
Parameters
$from : string

The '_key' or '_id' of the vertex to start from.

$to : string

The '_key' or '_id' of the target vertex to check for.

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

Optional array of query options (e.g., AQL::GRAPH).

Tags
throws
ArangoException
BindException
ContainerExceptionInterface
DependencyException
NotFoundException
NotFoundExceptionInterface
ReflectionException
ConstantException
Return values
bool

True if the target vertex is an outbound neighbor, false otherwise.

initializeArrays()

Initialize the per-field embedded-array configuration from the `arrays` option.

public initializeArrays([array<string|int, mixed> $init = [] ]) : static

Each entry is either an ArrayMode shorthand ('tags' => ArrayMode::SET) or a richer definition ('tracks' => [ ArrayMode::LIST , Arango::COUNTER => 'numberOfTracks' ]).

Parameters
$init : array<string|int, mixed> = []
Return values
static

initializeDocumentsMethods()

Initialize the Documents HTTP methods signals.

public initializeDocumentsMethods() : static
Return values
static

initializeFields()

Initialize fields definitions from an associative array.

public initializeFields([array<string, mixed> $init = [] ]) : static
Parameters
$init : array<string, mixed> = []

Optional initialization array containing a 'fields' key.

Return values
static

initializePurge()

Initialize the purge property from an array or string.

public initializePurge([array<string|int, mixed>|string|null $init = null ]) : static
Parameters
$init : array<string|int, mixed>|string|null = null

If array, looks for the key AQL::PURGE; if string, directly sets the purge mode.

Return values
static

insertEdge()

Inserts a new edge document connecting two vertices, optionally checking for uniqueness.

public insertEdge(string $from, string $to[, array<string|int, mixed> $doc = [] ][, array<string|int, mixed> $init = [] ]) : object|null

Constructs the edge document (_from, _to, attributes) and delegates to the generic insert() method. By default, it first checks if an edge with the same _from and _to already exists using existEdge() and throws an Error409 if found. This behavior can be disabled via the AQL::UNIQUE option.

Parameters
$from : string

The _key or full _id of the source vertex. Resolved using $this->from context if only a key is given.

$to : string

The _key or full _id of the target vertex. Resolved using $this->to context if only a key is given.

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

Optional additional document to complete the edge document (e.g., ['createdAt' => time()]).

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

Optional array for query options:

  • AQL::UNIQUE (bool) : If true (default), checks for an existing edge between $from and $to before inserting. Throws Error409 if found. If false, attempts direct insert (faster, relies on DB index or allows duplicates).
  • AQL::OPTIONS (array): Options passed to the underlying ArangoDB INSERT operation (see InsertOptions).
  • Other options accepted by the underlying insert() method (e.g., AQL::EXCLUDES).
Tags
throws
ArangoException

If the underlying AQL query execution fails.

BindException

If binding variables fails during the insert() process.

ContainerExceptionInterface
DateInvalidTimeZoneException
DateMalformedStringException
DependencyException
Error409

If AQL::UNIQUE is true and an edge already exists between the resolved $from and $to.

NotFoundException
NotFoundExceptionInterface
ReflectionException
UnsupportedOperationException
Throwable
example
$edges = new Edges($container, ['collection' => 'user_follows']);

// Insert, will throw Error409 if edge already exists
try
{
    $newEdge = $edges->insertEdge('users/1', 'users/2', ['since' => date('Y-m-d')]);
    if ($newEdge)
    {
        echo "Edge created with _id: " . $newEdge->_id;
    }
} catch ( Error409 $e )
{
     echo "$e->getMessage() ;
}

// Insert without checking uniqueness
$newEdgeUnchecked = $edges->insertEdge('users/1', 'users/3', [], [ AQL::UNIQUE => false ]);
Return values
object|null

The newly inserted edge document object , or null on failure.

prepareQueryFields()

Prepares query fields based on internal definitions and optional skin filter.

public prepareQueryFields([array<string|int, mixed>|null $fields = null ][, string|null $skin = null ][, string|null $parentKey = null ][, string|array<string|int, mixed>|null $in = null ]) : array<string, array<string|int, mixed>>|null

Converts string filters to array format, applies skins, and normalizes each field.

Parameters
$fields : array<string|int, mixed>|null = null

Optional custom fields to process (defaults to $this->fields).

$skin : string|null = null

Optional skin to filter applicable fields.

$parentKey : string|null = null

Optional parent key definition.

$in : string|array<string|int, mixed>|null = null

Optional field or list of fields to filter the final fields definitions.

Tags
example
$fields = $model->prepareQueryFields('full');
// Returns normalized array of fields including only those matching the 'full' skin
Return values
array<string, array<string|int, mixed>>|null

Normalized fields ready for query, or null if none.

repair()

Reconciles the server with everything this model declares — the acting half of {@see diagnose()}:

public repair([bool $force = false ]) : array<string|int, DiffReport>
  1. a missing collection is created with its declared type and its declared indexes (exactly what the lazy provisioning would do);
  2. missing indexes are created on an existing collection — the case the lazy provisioning never covers; a drifted index is only rebuilt (drop + recreate) when $force is true, because the rebuild opens a window where queries lose the index and a unique index may fail to recreate over duplicated data;
  3. the View is created or resynchronized through SearchTrait::viewSync() (updateProperties(), the View stays queryable while re-indexing).

DiffStatus::INVALID and DiffStatus::UNREACHABLE reports are never acted on; a drifted collection type is never repaired (recreating a collection means losing its documents — that is a migration, not a repair).

Parameters
$force : bool = false

Allow the drop + recreate of drifted indexes.

Tags
throws
ReflectionException

When a declared IndexOptions cannot be serialised.

Return values
array<string|int, DiffReport>

The diagnose() reports, with $applied set on every object actually created or updated.

returnFields()

Generates an AQL document expression or LET statement with the selected fields.

public returnFields([array<string, mixed> $init = [] ][, array<string|int, mixed> &$variables = [] ][, bool $isVariable = false ]) : string

Supports edges, joins, skins, and query fields.

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

Options to customize the query:

  • string|array $fields: comma-separated list or array of field names
  • ?array $queryFields: prepared query fields (overrides internal $fields)
  • ?string $lang: optional language key
  • string $docRef: document reference name
  • bool $isResult: whether to assign to result variable
$variables : array<string|int, mixed> = []
$isVariable : bool = false

Whether to generate a LET statement instead of RETURN

Tags
throws
ContainerExceptionInterface
NotFoundExceptionInterface
Exception
example
$aql = $model->returnFields
([
    Arango::QUERY_FIELDS => $queryFields,
    Arango::DOC_REF      => 'doc',
    Arango::SKIN         => 'full'
]);
Return values
string

Compiled AQL query fragment

arrayCounter()

Returns the configured length-counter attribute of an array field, or null.

protected arrayCounter(string|null $field) : string|null
Parameters
$field : string|null
Return values
string|null

arrayMode()

Resolves the {@see ArrayMode} of an array field, honouring an optional per-call `mode` override, then the declared configuration, then defaulting to LIST.

protected arrayMode(string|null $field[, array<string|int, mixed> $init = [] ]) : string
Parameters
$field : string|null
$init : array<string|int, mixed> = []
Return values
string

arrayWith()

Builds the `WITH { ... }` object clause: the array field, its optional length counter, and the `modified` timestamp unless `touch` is disabled.

protected arrayWith(string|null $field, string $arrayVar[, array<string|int, mixed> $init = [] ]) : string
Parameters
$field : string|null

The array attribute name.

$arrayVar : string

The AQL variable holding the new array (e.g. '__arr').

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

countEdgesQuery()

Generates the count query and fill the binds array reference.

protected countEdgesQuery([string|null $from = null ][, string|null $to = null ][, array<string|int, mixed> &$binds = [] ][, array<string|int, mixed> $init = [] ]) : string
Parameters
$from : string|null = null

The from vertex identifier

$to : string|null = null

The to vertex identifier

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

The bindVars array reference.

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

The option of the method.

  • 'collection' : The name of the collection, by default use the $this->collection property.
  • 'name' : The name of the bindVariable collection, by default use the @@collection.
  • '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
throws
BindException
ReflectionException
example
[ $query , $binds ] = $this->countEdgeQuery( $from , $to ) ;
Return values
string

The AQL query expression.

ensureArrayDefaults()

Builds an `ensure` closure that seeds the declared array fields to `[]` (and their counters to `0`) for any missing key of a document being created, then applies the optional user-supplied `ensure`. Returns the user closure unchanged when no array field is declared (so models without `AQL::ARRAYS` are untouched).

protected ensureArrayDefaults([Closure|null $ensure = null ]) : Closure|null
Parameters
$ensure : Closure|null = null

An optional user ensure closure to compose with.

Return values
Closure|null

filterFieldsBySkin()

Filters fields based on an optional skin.

private filterFieldsBySkin(array<string, mixed> $fields, string|null $skin) : array<string, mixed>
Parameters
$fields : array<string, mixed>

Fields to filter

$skin : string|null

Skin to match

Return values
array<string, mixed>

Filtered fields

generateUniqueKey()

Generates a unique key for special filters like edges, joins, or unique names.

private generateUniqueKey(string $key, string|null $filter[, string|null $parentKey = null ]) : string|null
Parameters
$key : string

Base field key

$filter : string|null

Filter type

$parentKey : string|null = null

Optional parent key.

Return values
string|null

Generated unique key or existing

hasVertex()

Private helper to check for vertex existence in a specific direction.

private hasVertex(string $direction, string $startVertex, string $targetVertex[, array<string|int, mixed> $init = [] ]) : bool

This method builds the filter query to check if a $targetVertex exists in the results of a traversal from $startVertex.

Parameters
$direction : string

Traversal::OUTBOUND, Traversal::INBOUND, or Traversal::ANY

$startVertex : string

The _key or _id of the vertex to start from.

$targetVertex : string

The _key or _id of the vertex to find.

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

Optional query options.

Tags
throws
ArangoException
BindException
ConstantException
ContainerExceptionInterface
DependencyException
NotFoundException
NotFoundExceptionInterface
ReflectionException
Return values
bool

normalizeFieldDefinition()

Normalize a field definition into a structured array for queries.

private normalizeFieldDefinition(string $key[, array<string|int, mixed> $options = [] ][, string|null $parentKey = null ]) : array<string, mixed>
  • Converts string filters to array
  • Handles subfields for DOCUMENT or MAP filters
  • Generates unique keys for special filters
Parameters
$key : string

Field name

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

Field options, may include:

  • Field::FILTER
  • Field::NAME
  • Field::QUOTED
  • Field::FIELDS (for DOCUMENT or MAP)
$parentKey : string|null = null

The Optional parent key

Tags
example
$normalized = $this->normalizeFieldDefinition( 'permissions',
[
    Field::FILTER => Filter::EDGES,
    Field::SKINS => [Skin::FULL]
]);
Return values
array<string, mixed>

Normalized field definition

runArrayUpdate()

Compiles and executes a single-document array UPDATE (`FOR ... FILTER ... LET ... UPDATE ... RETURN NEW`), emitting the update signals around the write.

private runArrayUpdate(string|null $field, array<string|int, mixed> $lets, string $filter, array<string|int, mixed> &$binds, array<string|int, mixed> $init) : object|null
Parameters
$field : string|null

The array attribute name.

$lets : array<string|int, mixed>

The ordered LET clauses producing the __arr variable.

$filter : string

The FILTER predicate locating the document.

$binds : array<string|int, mixed>

The bind variables (mutated by reference).

$init : array<string|int, mixed>
Tags
throws
ArangoException
BindException
ContainerExceptionInterface
DependencyException
NotFoundException
NotFoundExceptionInterface
ReflectionException
Throwable
Return values
object|null
On this page

Search results