Oihana PHP Arango

ArangoProcessTrait

Builds and runs the `arangodump` / `arangorestore` external processes **without going through a shell**.

The previous implementation passed a single string (assembled by the options serializer, which only json_encodes values) to system(). Inside a shell, that string is re-parsed: a value containing $(…), backticks, spaces or quotes would break the command — or inject arbitrary shell. Building an explicit argument vector and handing it to proc_open() (array form, available since PHP 7.4) bypasses the shell entirely, so option values are passed verbatim as argv entries and can never be re-interpreted.

Tags
author

Marc Alcaraz (ekameleon)

since
1.0.0

Table of Contents

Methods

optionsToArguments()  : array<int, string>
Converts an {@see Options} object into a flat argument vector, using the same flag mapping as the string serializer (prefix + {@see Option::getCommandOption()}), but keeping each value as its own `argv` entry instead of quoting it into a shell string.
runProcess()  : int
Runs an external process from an argument vector, without a shell.

Methods

optionsToArguments()

Converts an {@see Options} object into a flat argument vector, using the same flag mapping as the string serializer (prefix + {@see Option::getCommandOption()}), but keeping each value as its own `argv` entry instead of quoting it into a shell string.

protected static optionsToArguments(Options $options, Option> $optionClass) : array<int, string>
  • array value → the flag is repeated for each item (--collection a --collection b);
  • boolean true → the bare flag (--create-collection);
  • boolean false → flag followed by the literal false;
  • scalar value → flag followed by the value, as a single argv entry.

Null and empty values are dropped (handled by Options::toArray()).

Parameters
$options : Options

The options to serialize.

$optionClass : Option>

The Option subclass providing the flag mapping.

Tags
throws
ReflectionException
Return values
array<int, string>

runProcess()

Runs an external process from an argument vector, without a shell.

protected static runProcess(array<int, string> $arguments[, bool $silent = false ]) : int

stdin/stdout/stderr are inherited from the parent process so the native arangodump / arangorestore progress output stays visible, unless $silent redirects stdout/stderr to the null device.

Parameters
$arguments : array<int, string>

The argv (argv[0] = binary name).

$silent : bool = false

Whether to discard the process output.

Tags
throws
RuntimeException

When the process cannot be started.

Return values
int

The process exit code.

On this page

Search results