Oihana PHP Arango

EdgesFromTrait uses trait:short

Provides utilities for initialize edge `from` vertex references in ArangoDB edge queries.

This trait manages the source ('from') vertex models for edge collections. It allows initializing these references from arrays or PSR-11.

Tags
author

Marc Alcaraz

version
1.0.0

Table of Contents

Constants

ON_DELETE_VERTEX  : string = 'onDeleteVertex'
Constant for the method name to hook deletion events.

Properties

$from  : Documents|null
The source document collection model (vertex where edges originate).

Methods

initializeFrom()  : static
Initialize the 'from' reference.
onDeleteVertex()  : void
Invoked when a vertex document is deleted.
registerFrom()  : $this
Register the `from` Documents signals.
releaseFrom()  : static
Release the 'from' reference.
unregisterFrom()  : $this
Unregister the `from` Documents signals.
purgeVertices()  : void
Purge related vertex documents based on the defined purge direction.

Constants

ON_DELETE_VERTEX

Constant for the method name to hook deletion events.

public string ON_DELETE_VERTEX = 'onDeleteVertex'

Properties

$from

The source document collection model (vertex where edges originate).

public Documents|null $from = null

Methods

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
throws
ContainerExceptionInterface
NotFoundExceptionInterface
Return values
static

onDeleteVertex()

Invoked when a vertex document is deleted.

public onDeleteVertex(Payload $payload) : void

This method :

  • Deletes all edges of the specific document resource ;
  • Determinates which related vertex documents to purge based on the $purge property ;
Parameters
$payload : Payload

The payload containing:

  • data : The deleted vertex or array of vertices.
  • target: The vertex model (from or to) from which deletion originates.
Tags
throws
Throwable

Example:

$payload = new Payload(data: $deletedVertex, target: $edge->from);
$edge->onDeleteVertex($payload);

registerFrom()

Register the `from` Documents signals.

public registerFrom() : $this
Return values
$this

releaseFrom()

Release the 'from' reference.

public releaseFrom() : static
Return values
static

unregisterFrom()

Unregister the `from` Documents signals.

public unregisterFrom() : $this
Return values
$this

purgeVertices()

Purge related vertex documents based on the defined purge direction.

private purgeVertices(array<string|int, mixed> $edges, object $target) : void

This method is automatically called by onDeleteVertex() after an edge's vertex has been deleted.

Usage

For example, suppose you have a WebAPI document connected to several Permission documents via edges. If you delete the WebAPI document and the purge mode is set to Purge::OUTBOUND or Purge::BOTH, all connected Permission vertices in their collection will be automatically removed.

Similarly, if a Permission vertex is deleted and the purge mode is Purge::INBOUND or Purge::BOTH, the related WebAPI vertices will be deleted according to the purge direction.

Graph illustration of purge directions

OUTBOUND (delete TO when FROM is deleted): [FROM: WebAPI] ---> [TO: Permission] DELETE WebAPI -> automatically DELETE Permission(s)

INBOUND (delete FROM when TO is deleted): [FROM: WebAPI] ---> [TO: Permission] DELETE Permission -> automatically DELETE WebAPI

BOTH (delete both sides): [FROM: WebAPI] ---> [TO: Permission] DELETE WebAPI -> DELETE Permission DELETE Permission -> DELETE WebAPI

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

Array of edge documents returned by deleteEdges().

$target : object

The vertex model that triggered the deletion.

Return values
void

Example:

$edges = $edge->deleteEdges(vertex: $vertexKeys, init: [AQL::CONTEXT => $edge->from]);
$edge->purgeVertices($edges, $edge->from);
On this page

Search results