Class kartik\wordreport\utils\Command
Inheritance | kartik\wordreport\utils\Command » yii\base\Component » yii\base\BaseObject |
---|---|
Implements | yii\base\Configurable |
This Command library helps managing and executing shell commands. Modified version of the Command class from mikehaertl/php-shellcommand.
Public Properties
Property | Type | Description | Defined By |
---|---|---|---|
$args | string | The command args that where set with setArgs() or added with addArg() separated by spaces | kartik\wordreport\utils\Command |
$behaviors | yii\base\Behavior[] | List of behaviors attached to this component. | yii\base\Component |
$captureStdErr | boolean | Whether to capture stderr (2>&1) when useExec is true. |
kartik\wordreport\utils\Command |
$command | string|null | The command that was set through setCommand() or passed to the constructor. | kartik\wordreport\utils\Command |
$error | string | The error message, either stderr or an internal message. | kartik\wordreport\utils\Command |
$escapeArgs | boolean | Whether to escape any argument passed through addArg() . |
kartik\wordreport\utils\Command |
$escapeCommand | boolean | Whether to escape the command passed to setCommand() or the
constructor. |
kartik\wordreport\utils\Command |
$execCommand | string|boolean | The full command string to execute. | kartik\wordreport\utils\Command |
$exitCode | integer|null | The exit code or null if command was not executed yet | kartik\wordreport\utils\Command |
$isExecuted | boolean | Whether the command was successfully executed | kartik\wordreport\utils\Command |
$isWindows | boolean | Whether we are on a Windows OS | kartik\wordreport\utils\Command |
$locale | null|string | The locale to temporarily set before calling
escapeshellargs() . |
kartik\wordreport\utils\Command |
$nonBlockingMode | boolean|null | Whether to set the stdin/stdout/stderr streams to
non-blocking mode when proc_open() is used. |
kartik\wordreport\utils\Command |
$output | string | The command output (stdout). | kartik\wordreport\utils\Command |
$postExecuteScript | string | Post execution scripts that will be executed after the command and separated by && (only for non windows) | kartik\wordreport\utils\Command |
$preExecuteScript | string | Pre execution scripts that will be executed before the command and separated by && (only for non windows) | kartik\wordreport\utils\Command |
$procCwd | string|null | The initial working dir for proc_open() . |
kartik\wordreport\utils\Command |
$procEnv | array|null | An array with environment variables to pass to
proc_open() . |
kartik\wordreport\utils\Command |
$procOptions | array|null | An array of other_options for proc_open() . |
kartik\wordreport\utils\Command |
$stdErr | string | The stderr output. | kartik\wordreport\utils\Command |
$stdIn | string|resource | If set, the string will be piped to the command via standard input. | kartik\wordreport\utils\Command |
$timeout | integer | The time in seconds after which a command should be terminated. | kartik\wordreport\utils\Command |
$useExec | boolean | Whether to use exec() instead of proc_open() . |
kartik\wordreport\utils\Command |
Protected Properties
Property | Type | Description | Defined By |
---|---|---|---|
$_args | array | The list of command arguments | kartik\wordreport\utils\Command |
$_command | string | The command to execute | kartik\wordreport\utils\Command |
$_error | string | The error message | kartik\wordreport\utils\Command |
$_execCommand | string | The full command string to execute | kartik\wordreport\utils\Command |
$_executed | boolean | Whether the command was successfully executed | kartik\wordreport\utils\Command |
$_exitCode | integer | The exit code | kartik\wordreport\utils\Command |
$_stdErr | string | The stderr output | kartik\wordreport\utils\Command |
$_stdIn | null|string|resource | To pipe to standard input | kartik\wordreport\utils\Command |
$_stdOut | string | The stdout output | kartik\wordreport\utils\Command |
Public Methods
Method | Description | Defined By |
---|---|---|
__call() | Calls the named method which is not a class method. | yii\base\Component |
__clone() | This method is called after the object is created by cloning an existing one. | yii\base\Component |
__construct() | Constructor. | yii\base\BaseObject |
__get() | Returns the value of a component property. | yii\base\Component |
__isset() | Checks if a property is set, i.e. defined and not null. | yii\base\Component |
__set() | Sets the value of a component property. | yii\base\Component |
__unset() | Sets a component property to be null. | yii\base\Component |
addArg() | kartik\wordreport\utils\Command | |
attachBehavior() | Attaches a behavior to this component. | yii\base\Component |
attachBehaviors() | Attaches a list of behaviors to the component. | yii\base\Component |
behaviors() | Returns a list of behaviors that this component should behave as. | yii\base\Component |
canGetProperty() | Returns a value indicating whether a property can be read. | yii\base\Component |
canSetProperty() | Returns a value indicating whether a property can be set. | yii\base\Component |
className() | Returns the fully qualified name of this class. | yii\base\BaseObject |
detachBehavior() | Detaches a behavior from the component. | yii\base\Component |
detachBehaviors() | Detaches all behaviors from the component. | yii\base\Component |
ensureBehaviors() | Makes sure that the behaviors declared in behaviors() are attached to this component. | yii\base\Component |
execute() | Execute the command | kartik\wordreport\utils\Command |
getArgs() | kartik\wordreport\utils\Command | |
getBehavior() | Returns the named behavior object. | yii\base\Component |
getBehaviors() | Returns all behaviors attached to this component. | yii\base\Component |
getCommand() | kartik\wordreport\utils\Command | |
getError() | kartik\wordreport\utils\Command | |
getExecCommand() | kartik\wordreport\utils\Command | |
getExitCode() | kartik\wordreport\utils\Command | |
getIsExecuted() | kartik\wordreport\utils\Command | |
getIsWindows() | kartik\wordreport\utils\Command | |
getOutput() | kartik\wordreport\utils\Command | |
getStdErr() | kartik\wordreport\utils\Command | |
hasEventHandlers() | Returns a value indicating whether there is any handler attached to the named event. | yii\base\Component |
hasMethod() | Returns a value indicating whether a method is defined. | yii\base\Component |
hasProperty() | Returns a value indicating whether a property is defined for this component. | yii\base\Component |
init() | Initializes the object. | yii\base\BaseObject |
off() | Detaches an existing event handler from this component. | yii\base\Component |
on() | Attaches an event handler to an event. | yii\base\Component |
setArgs() | kartik\wordreport\utils\Command | |
setCommand() | kartik\wordreport\utils\Command | |
setStdIn() | kartik\wordreport\utils\Command | |
trigger() | Triggers an event. | yii\base\Component |
Property Details
The list of command arguments
The command to execute
The error message
The full command string to execute
Whether the command was successfully executed
The exit code
The stderr output
To pipe to standard input
The stdout output
The command args that where set with setArgs() or added with addArg() separated by spaces
Whether to capture stderr (2>&1) when useExec
is true. This
will try to redirect the stderr to stdout and provide the complete
output of both in getStdErr()
and getError()
. Default is true
.
The command that was set through setCommand() or
passed to the constructor. null
if none.
The error message, either stderr or an internal message. Empty string if none.
Whether to escape any argument passed through addArg()
.
Default is true
.
Whether to escape the command passed to setCommand()
or the
constructor. This is only useful if $escapeArgs
is false
. Default
is false
.
The full command string to execute. If no command
was set with setCommand() or passed to the constructor it will return
false
.
The exit code or null if command was not executed yet
Whether the command was successfully executed
Whether we are on a Windows OS
The locale to temporarily set before calling
escapeshellargs()
. Default is null
for none.
Whether to set the stdin/stdout/stderr streams to
non-blocking mode when proc_open()
is used. This allows to have huge
inputs/outputs without making the process hang. The default is null
which will enable the feature on Non-Windows systems. Set it to true
or false
to manually enable/disable it. It does not work on Windows.
The command output (stdout). Empty if none.
Post execution scripts that will be executed after the command and separated by && (only for non windows)
Pre execution scripts that will be executed before the command and separated by && (only for non windows)
The initial working dir for proc_open()
. Default is
null
for current PHP working dir.
An array with environment variables to pass to
proc_open()
. Default is null
for none.
An array of other_options for proc_open()
. Default is
null
for none.
The stderr output. Empty if none.
If set, the string will be piped to the command via standard input. This enables the same functionality as piping on the command line. It can also be a resource like a file handle or a stream in which case its content will be piped into the command like an input redirection.
The time in seconds after which a command should be terminated.
This only works in non-blocking mode. Default is null
which means the
process is never terminated.
Whether to use exec()
instead of proc_open()
. This can be
used on Windows system to workaround some quirks there. Note, that any
errors from your command will be output directly to the PHP output
stream. getStdErr()
will also not work anymore and thus you also won't
get the error output from getError()
in this case. You also can't pass
any environment variables to the command if this is enabled. Default is
false
.
Method Details
public static addArg ( $key, $value = null, $escape = null ) | ||
$key | string | The argument key to add e.g. |
$value | string|array|null | The optional argument value which will
get escaped if $escapeArgs is true. An array can be passed to add more
than one value for a key, e.g. |
$escape | boolean|null | If set, this overrides the $escapeArgs setting and enforces escaping/no escaping |
return | static | For method chaining |
---|
Execute the command
public boolean execute ( ) | ||
return | boolean | Whether execution was successful. If |
---|
public string getArgs ( ) | ||
return | string | The command args that where set with setArgs() or added with addArg() separated by spaces |
---|
public string|null getCommand ( ) | ||
return | string|null | The command that was set through setCommand() or
passed to the constructor. |
---|
public string getError ( $trim = true ) | ||
$trim | boolean | Whether to |
return | string | The error message, either stderr or an internal message. Empty string if none. |
---|
public string|boolean getExecCommand ( ) | ||
return | string|boolean | The full command string to execute. If no command
was set with setCommand() or passed to the constructor it will return
|
---|
public integer|null getExitCode ( ) | ||
return | integer|null | The exit code or null if command was not executed yet |
---|
public boolean getIsExecuted ( ) | ||
return | boolean | Whether the command was successfully executed |
---|
public boolean getIsWindows ( ) | ||
return | boolean | Whether we are on a Windows OS |
---|
public string getOutput ( $trim = true ) | ||
$trim | boolean | Whether to |
return | string | The command output (stdout). Empty if none. |
---|
public string getStdErr ( $trim = true ) | ||
$trim | boolean | Whether to |
return | string | The stderr output. Empty if none. |
---|
public static setArgs ( $args ) | ||
$args | string | The command arguments as string. Note that these will not get escaped! |
return | static | For method chaining |
---|
public static setCommand ( $command ) | ||
$command | string | The command or full command string to execute, like 'gzip' or 'gzip -d'. You can still call addArg() to add more arguments to the command. If $escapeCommand was set to true, the command gets escaped with escapeshellcmd(). |
return | static | For method chaining |
---|
public static setStdIn ( $stdIn ) | ||
$stdIn | string|resource | If set, the string will be piped to the command via standard input. This enables the same functionality as piping on the command line. It can also be a resource like a file handle or a stream in which case its content will be piped into the command like an input redirection. |
return | static | For method chaining |
---|