Oihana PHP Arango

decodeRevision.php

Table of Contents

Functions

decodeRevision()  : array<string|int, mixed>|null
Decompose the specified revision string into its components.

Functions

decodeRevision()

Decompose the specified revision string into its components.

decodeRevision(string|null $revision[, bool $throwable = false ]) : array<string|int, mixed>|null

The resulting object has a date and a count attribute. This function is supposed to be called with the _rev attribute value of a database document as argument.

Decodes an ArangoDB revision string (_rev) into a timestamp and a counter.

This function implements the C++ algorithm used by ArangoDB to decode the _rev string into a 64-bit integer, then splits it into a timestamp (milliseconds since epoch) and a counter. The result is returned as an associative array with 'date' (ISO 8601 format) and 'count' (integer).

Parameters
$revision : string|null

The ArangoDB revision string (e.g., "jGPSg12---"). Must be 10 or 11 characters long, start with '', and contain at least one letter.

$throwable : bool = false

If true, throws exceptions on error. If false, returns null on error.

Tags
throws
InvalidArgumentException

If $revision is null or empty and $throwable is true.

RuntimeException

If $revision is invalid (wrong length, format, or content) and $throwable is true, or if the GMP extension is not loaded and $throwable is true.

example

Example usage:

$revision = '_jGPSg12---';
$result = decodeRevision($revision);
// $result = ['date' => '2025-01-20T15:28:40.830Z', 'count' => 0]

Example with invalid revision (returns null or throws exception):

$result = decodeRevision('_1234567890', true); // Throws RuntimeException
$result = decodeRevision('_1234567890');      // Returns null
see
https://docs.arangodb.com/3.11/aql/functions/miscellaneous/#decode_rev
encodeRevision()

For encoding a _rev string with a specific date and an optional count value.

author

Marc Alcaraz (eKameleon)

version
1.0.0
Return values
array<string|int, mixed>|null

Returns an associative array with 'date' and 'count' keys on success, or null on failure. Example return value: ['date' => '2025-01-20T15:28:40.830Z', 'count' => 0]. Returns null if the input is invalid or if the GMP extension is not loaded.

On this page

Search results