trait ExecCommand (View source)

This task is supposed to be executed as shell command.

You can specify working directory and if output is printed.

Traits

Class ExecTrait

Properties

protected bool $background from  ExecTrait
protected null|int $timeout from  ExecTrait
protected null|int $idleTimeout from  ExecTrait
protected null|array $env from  ExecTrait
protected Process $process from  ExecTrait
protected resource|string $input from  ExecTrait
protected bool $interactive from  ExecTrait
protected bool $isPrinted from  ExecTrait
protected bool $isMetadataPrinted from  ExecTrait
protected string $workingDirectory from  ExecTrait
protected TimeKeeper $execTimer

Methods

getCommandDescription()

{@inheritdoc}

startTimer()

No description

stopTimer()

No description

null|float
getExecutionTime()

No description

bool
hideTaskProgress()

No description

showTaskProgress(bool $inProgress)

No description

printTaskInfo(string $text, null|array $context = null)

No description

bool
verbosityMeetsThreshold()

No description

writeMessage(string $message)

No description

$this
detectInteractive()

Sets $this->interactive() based on posix_isatty().

$this
background(bool $arg = true)

Executes command in background mode (asynchronously)

$this
timeout(int $timeout)

Stop command if it runs longer then $timeout in seconds

$this
idleTimeout(int $timeout)

Stops command if it does not output something for a while

$this
env(string|array $env, bool|string $value = null)

Set a single environment variable, or multiple.

$this
envVars(array $env)

Sets the environment variables for the command

$this
setProcessInput(resource|string $input)

Pass an input to the process. Can be resource created with fopen() or string

$this
setInput(resource|string $input) deprecated

Pass an input to the process. Can be resource created with fopen() or string

$this
interactive(bool $interactive = true)

Attach tty to process for interactive input

bool
getPrinted()

Is command printing its output to screen

$this
dir(string $dir)

Changes working directory of command

$this
silent(bool $arg)

Shortcut for setting isPrinted() and isMetadataPrinted() to false.

$this
printed(bool $arg) deprecated

Should command output be printed

$this
printOutput(bool $arg)

Should command output be printed

$this
printMetadata(bool $arg)

Should command metadata be printed. I,e., command and timer.

execute(Process $process, callable $output_callback = null)

No description

stop()

No description

printAction(array $context = [])

No description

string
formatCommandDisplay(string $command)

No description

array
getResultData()

Gets the data array to be passed to Result().

getExecTimer()

No description

bool|string
findExecutablePhar(string $cmd)

Look for a "{$cmd}.phar" in the current working directory; return a string to exec it if it is found. Otherwise, look for an executable command of the same name via findExecutable.

bool|string
findExecutable(string $cmd)

Return the best path to the executable program with the provided name. Favor vendor/bin in the current project. If not found there, use whatever is on the $PATH.

bool|string
findProjectBin()

No description

string
useCallOnWindows(string $cmd)

Wrap Windows executables in 'call' per 7a88757d

executeCommand(string $command)

No description

Details

protected getCommandDescription()

{@inheritdoc}

abstract protected startTimer()

No description

abstract protected stopTimer()

No description

abstract protected null|float getExecutionTime()

No description

Return Value

null|float

See also

ProgressIndicatorAwareTrait
Timer

abstract protected bool hideTaskProgress()

No description

Return Value

bool

See also

TaskIO

abstract protected showTaskProgress(bool $inProgress)

No description

Parameters

bool $inProgress

See also

TaskIO

abstract protected printTaskInfo(string $text, null|array $context = null)

No description

Parameters

string $text
null|array $context

See also

TaskIO

abstract bool verbosityMeetsThreshold()

No description

Return Value

bool

See also

VerbosityThresholdTrait

abstract writeMessage(string $message)

No description

Parameters

string $message

See also

VerbosityThresholdTrait

$this detectInteractive()

Sets $this->interactive() based on posix_isatty().

Return Value

$this

$this background(bool $arg = true)

Executes command in background mode (asynchronously)

Parameters

bool $arg

Return Value

$this

$this timeout(int $timeout)

Stop command if it runs longer then $timeout in seconds

Parameters

int $timeout

Return Value

$this

$this idleTimeout(int $timeout)

Stops command if it does not output something for a while

Parameters

int $timeout

Return Value

$this

$this env(string|array $env, bool|string $value = null)

Set a single environment variable, or multiple.

Parameters

string|array $env
bool|string $value

Return Value

$this

$this envVars(array $env)

Sets the environment variables for the command

Parameters

array $env

Return Value

$this

$this setProcessInput(resource|string $input)

Pass an input to the process. Can be resource created with fopen() or string

Parameters

resource|string $input

Return Value

$this

$this setInput(resource|string $input) deprecated

deprecated

Pass an input to the process. Can be resource created with fopen() or string

Parameters

resource|string $input

Return Value

$this

$this interactive(bool $interactive = true)

Attach tty to process for interactive input

Parameters

bool $interactive

Return Value

$this

bool getPrinted()

Is command printing its output to screen

Return Value

bool

$this dir(string $dir)

Changes working directory of command

Parameters

string $dir

Return Value

$this

$this silent(bool $arg)

Shortcut for setting isPrinted() and isMetadataPrinted() to false.

Parameters

bool $arg

Return Value

$this

$this printed(bool $arg) deprecated

deprecated

Should command output be printed

Parameters

bool $arg

Return Value

$this

$this printOutput(bool $arg)

Should command output be printed

Parameters

bool $arg

Return Value

$this

$this printMetadata(bool $arg)

Should command metadata be printed. I,e., command and timer.

Parameters

bool $arg

Return Value

$this

protected ResultData execute(Process $process, callable $output_callback = null)

No description

Parameters

Process $process
callable $output_callback

Return Value

ResultData

protected stop()

No description

protected printAction(array $context = [])

No description

Parameters

array $context

protected string formatCommandDisplay(string $command)

No description

Parameters

string $command

Return Value

string

protected array getResultData()

Gets the data array to be passed to Result().

Return Value

array

The data array passed to Result().

protected TimeKeeper getExecTimer()

No description

Return Value

TimeKeeper

protected bool|string findExecutablePhar(string $cmd)

Look for a "{$cmd}.phar" in the current working directory; return a string to exec it if it is found. Otherwise, look for an executable command of the same name via findExecutable.

Parameters

string $cmd

Return Value

bool|string

protected bool|string findExecutable(string $cmd)

Return the best path to the executable program with the provided name. Favor vendor/bin in the current project. If not found there, use whatever is on the $PATH.

Parameters

string $cmd

Return Value

bool|string

protected bool|string findProjectBin()

No description

Return Value

bool|string

protected string useCallOnWindows(string $cmd)

Wrap Windows executables in 'call' per 7a88757d

Parameters

string $cmd

Return Value

string

protected Result executeCommand(string $command)

No description

Parameters

string $command

Return Value

Result