Oihana PHP Arango

ArangoCollectionsTrait

Pure, side-effect-free helpers shared by the `command:arangodb` dump / restore / collections actions.

Everything here is deterministic and server-free so it can be unit tested in isolation:

  • normalizeCollections() turns the raw Symfony VALUE_IS_ARRAY input into a clean collection-name list, accepting both repeated flags (--collection a --collection b) and comma-separated values (--collection=a,b), or any mix of the two.
  • assertCollectionTargeting() guards the mutually-exclusive --collection / --ignore-collection pair (an arangodump constraint).
  • missingCollections() diffs a requested set against the set of collections actually present in the database (validation before a targeted dump).
  • sanitizeLabel() validates the optional --label suffix so it stays filesystem-safe.
  • getArchiveNameSuffix() builds the archive name suffix (-{database}[-partial][-{label}], without file extension) shared by the dump output name and the restore-by-date lookup.
Tags
author

Marc Alcaraz (ekameleon)

since
1.0.0

Table of Contents

Constants

PARTIAL_MARKER  : string = 'partial'
Marker appended to the archive name when the dump targets a subset of collections (either `--collection` or `--ignore-collection`).

Methods

assertCollectionTargeting()  : void
Asserts that `--collection` and `--ignore-collection` are not used together — `arangodump` rejects that combination.
excludeCollections()  : array<int, string>
Returns the available collection names minus the excluded ones, order-preserving (case-sensitive).
getArchiveNameSuffix()  : string
Builds the archive name suffix (without file extension) shared by the dump output name and the restore-by-date lookup.
isSystemCollection()  : bool
Returns true when the given name is an ArangoDB system collection (its name starts with an underscore, e.g. `_jobs`, `_apps`).
missingCollections()  : array<int, string>
Returns the requested collection names that are NOT present in the available set (case-sensitive, as ArangoDB collection names are).
normalizeCollections()  : array<int, string>
Normalizes a raw collection option into a clean, de-duplicated, order-preserving list of collection names.
sanitizeLabel()  : string|null
Validates and normalizes the optional archive label.

Constants

PARTIAL_MARKER

Marker appended to the archive name when the dump targets a subset of collections (either `--collection` or `--ignore-collection`).

public string PARTIAL_MARKER = 'partial'

Methods

assertCollectionTargeting()

Asserts that `--collection` and `--ignore-collection` are not used together — `arangodump` rejects that combination.

protected static assertCollectionTargeting(array<int, string> $collection, array<int, string> $ignore) : void
Parameters
$collection : array<int, string>
$ignore : array<int, string>
Tags
throws
InvalidArgumentException

When both lists are non-empty.

excludeCollections()

Returns the available collection names minus the excluded ones, order-preserving (case-sensitive).

protected static excludeCollections(array<int, string> $available, array<int, string> $exclude) : array<int, string>

Used to resolve --ignore-collection client-side: arangodump has no exclusion option, so the complement is computed here and passed back as an explicit --collection list.

Parameters
$available : array<int, string>

The collections that exist.

$exclude : array<int, string>

The collections to drop.

Return values
array<int, string>

getArchiveNameSuffix()

Builds the archive name suffix (without file extension) shared by the dump output name and the restore-by-date lookup.

protected static getArchiveNameSuffix(string $database[, bool $partial = false ][, string|null $label = null ]) : string

Shape: -{database}[-partial][-{label}], e.g.

  • -mydb (full dump)
  • -mydb-partial (targeted dump, no label)
  • -mydb-partial-pre-migration (targeted dump with a label)
Parameters
$database : string

The database name.

$partial : bool = false

Whether the dump targets a subset of collections.

$label : string|null = null

Optional label (validated via sanitizeLabel()).

Tags
throws
InvalidArgumentException

When the label is invalid.

Return values
string

isSystemCollection()

Returns true when the given name is an ArangoDB system collection (its name starts with an underscore, e.g. `_jobs`, `_apps`).

protected static isSystemCollection(string $name) : bool
Parameters
$name : string
Return values
bool

missingCollections()

Returns the requested collection names that are NOT present in the available set (case-sensitive, as ArangoDB collection names are).

protected static missingCollections(array<int, string> $requested, array<int, string> $available) : array<int, string>

Order-preserving and de-duplicated.

Parameters
$requested : array<int, string>

The collections asked for on the CLI.

$available : array<int, string>

The collections that actually exist.

Return values
array<int, string>

The unknown collection names (empty when all exist).

normalizeCollections()

Normalizes a raw collection option into a clean, de-duplicated, order-preserving list of collection names.

protected static normalizeCollections(array<int|string, mixed> $raw) : array<int, string>

Accepts both syntaxes (and any mix):

  • repeated flags : ['users', 'products']
  • comma-separated : ['users,products']
  • mixed/with spaces : [' users , products ', 'customers']

Empty fragments are dropped; the first occurrence order is kept.

Parameters
$raw : array<int|string, mixed>
Return values
array<int, string>

sanitizeLabel()

Validates and normalizes the optional archive label.

protected static sanitizeLabel(string|null $label) : string|null

Returns null for a null/empty value. Otherwise the label must only contain letters, digits, dot, underscore and hyphen so it stays safe inside a filename.

Parameters
$label : string|null
Tags
throws
InvalidArgumentException

When the label contains unsafe characters.

Return values
string|null
On this page

Search results