Oihana PHP Arango

vertexID.php

Table of Contents

Functions

vertexID()  : string|null
Resolves a fully-qualified vertex ID for an ArangoDB edge.

Functions

vertexID()

Resolves a fully-qualified vertex ID for an ArangoDB edge.

vertexID(string|null $vertexKey[, Documents|string|null $collection = null ]) : string|null

Converts a vertex key into a complete ArangoDB vertex ID by optionally prefixing it with a collection name.

This is useful when preparing _from or _to fields in edge queries, ensuring the correct collection/key format.

Behavior

  • If $vertexKey is null, the function returns null.
  • If $collection is a Documents instance with a collection property, the returned ID will be prefixed with this collection.
  • If $collection is a string, it will be used directly as the collection prefix.
  • If $collection is null, the function returns the raw $vertexKey.
Parameters
$vertexKey : string|null

The vertex key (document _key) or null.

$collection : Documents|string|null = null

Optional collection prefix, either a string or a Documents instance.

Tags
example
use oihana\arango\models\Documents;
use function oihana\arango\models\helpers\vertexID;

$docs = new Documents();
$doc->collection = 'users';

$fullID = vertexID('123', $docs);
// → 'users/123'

$rawID = vertexID('456');
// → '456'

$stringPrefix = vertexID('789', 'accounts');
// → 'accounts/789'

$stringPrefix = vertexID('users/789', 'accounts');
// → 'users/789'

$stringPrefix = vertexID('accounts/789', $docs);
// → 'accounts/789'

$nullID = vertexID( null , $docs );
// → null
author

Marc Alcaraz (eKameleon)

version
1.0.0
Return values
string|null

Returns the prefixed vertex ID if a collection is provided, otherwise the original key, or null if $vertexKey is null.

On this page

Search results