ProcessBuilder

Class
Read only: Yes Final: Yes

Builds immutable process definitions from a command and a collection of arguments.

Description

This builder SHALL preserve previously supplied arguments by returning a new instance on each mutation-like operation. Implementations of this concrete builder MUST keep argument ordering stable so that the generated process reflects the exact sequence in which arguments were provided.

Table of Contents

Interfaces

ProcessBuilderInterface

Defines a fluent builder responsible for constructing process instances.

Properties

 : array<string|int, mixed>

Methods

__construct()

Creates a new immutable process builder instance.

 : mixed
build()

Builds a process instance for the specified command.

 : Process
getArguments()

Returns the arguments currently collected by the builder.

 : array<int, string>
withArgument()

Returns a new builder instance with an additional argument appended.

 : ProcessBuilderInterface
Properties

$arguments

Private
private array<string|int, mixed> $arguments = []
Methods

__construct()

Public

Creates a new immutable process builder instance.

public __construct([ array<int, string>  $arguments = []]) : mixed

Description

The provided arguments SHALL be stored in the same order in which they are received and MUST be used when building the final process instance.

Parameters
$arguments : array<int, string> = []

Description

the arguments already collected by the builder

build()

Public

Builds a process instance for the specified command.

public build( string|array<string|int, mixed>  $command) : Process

Description

The command string SHALL be split into tokens using a space separator and combined with all previously collected builder arguments. The resulting process MUST preserve the final token order exactly as assembled by this method.

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

Description

the base command used to initialize the process

Return values
Process

Description

the configured process instance ready for execution

getArguments()

Public

Returns the arguments currently collected by the builder.

public getArguments() : array<int, string>

Description

The returned list SHALL preserve insertion order and MAY be used for inspection, debugging, or testing purposes.

Return values
array<int, string>

Description

the collected process arguments

withArgument()

Public

Returns a new builder instance with an additional argument appended.

public withArgument( string  $argument[, string|null  $value = null]) : ProcessBuilderInterface

Description

When a value is provided, the argument SHALL be normalized to the "{argument}={value}" format before being appended. When no value is provided, the raw argument token MUST be appended as-is.

This method MUST NOT mutate the current builder instance and SHALL return a new instance containing the accumulated arguments.

Parameters
$argument : string

Description

the argument name or token to append

$value : string|null = null

Description

the optional value associated with the argument

Return values

Description

a new builder instance containing the appended argument