UnixCommand
in package
Fluent interface for building and running a command
Implementation is geared towards unix style executables and builtins
Tags
Table of Contents
- $env : Environment
- $executable : string
- $extraEnvironment : array<string|int, mixed>
- $logger : LoggerInterface
- $stack : array<string|int, mixed>
- __construct() : mixed
- __invoke() : ExecutionResultInterface
- __toString() : string
- Render the command as a string
- execute() : ExecutionResult
- Run the command to catch output and return code
- fromArray() : UnixCommand
- withArgument() : self
- Add an argument
- withEnvironmentVariable() : self
- withExecutable() : self
- withOption() : void
- Append an option to the command
- withOptionIfValue() : void
- Append an option to the command if a value is given
Properties
$env
private
Environment
$env
= new Environment()
$executable
private
string
$executable
$extraEnvironment
private
array<string|int, mixed>
$extraEnvironment
= []
$logger
private
LoggerInterface
$logger
= new NullLogger()
$stack
private
array<string|int, mixed>
$stack
= []
Methods
__construct()
public
__construct([Environment $env = new Environment() ][, LoggerInterface $logger = new NullLogger() ]) : mixed
Parameters
- $env : Environment = new Environment()
- $logger : LoggerInterface = new NullLogger()
Return values
mixed —__invoke()
public
__invoke([string $throwOnNonZero = '' ]) : ExecutionResultInterface
Parameters
- $throwOnNonZero : string = ''
Return values
ExecutionResultInterface —__toString()
Render the command as a string
public
__toString() : string
Return values
string —execute()
Run the command to catch output and return code
public
execute([string $throwOnNonZero = '' ]) : ExecutionResult
The STDERR (error) output will not be caught
Parameters
- $throwOnNonZero : string = ''
Return values
ExecutionResult —fromArray()
public
static fromArray(array<string|int, mixed> $args[, Environment $env = new Environment() ][, LoggerInterface $logger = new NullLogger() ]) : UnixCommand
Parameters
- $args : array<string|int, mixed>
- $env : Environment = new Environment()
- $logger : LoggerInterface = new NullLogger()
Return values
UnixCommand —withArgument()
Add an argument
public
withArgument(string $argument) : self
Values will be trimmed of leading/trailing whitespace. Values will not be shell escaped
Parameters
- $argument : string
Return values
self —withEnvironmentVariable()
public
withEnvironmentVariable(string $name, string $value) : self
Parameters
- $name : string
- $value : string
Return values
self —withExecutable()
public
withExecutable(string $name) : self
Parameters
- $name : string
Return values
self —withOption()
Append an option to the command
public
withOption(string $name[, string $value = null ]) : void
If the name is exactly one character, use a single hyphen -f If the name is longer, use two hyphens --foo If a value is provided, append it with equals --foo=bar
TODO: Shell-escape values
Parameters
- $name : string
- $value : string = null
Return values
void —withOptionIfValue()
Append an option to the command if a value is given
public
withOptionIfValue(string $name[, string $value = null ]) : void
If the name is exactly one character, use a single hyphen -f If the name is longer, use two hyphens --foo Append the value with equals --foo=bar If no value is provided, don't add the option at all
Parameters
- $name : string
- $value : string = null