PHP 클래스 mikehaertl\shellcommand\Command

This class represents a shell command.
저자: Michael Härtl ([email protected])
파일 보기 프로젝트 열기: mikehaertl/php-shellcommand 1 사용 예제들

공개 프로퍼티들

프로퍼티 타입 설명
$captureStdErr 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.
$escapeArgs whether to escape any argument passed through addArg(). Default is true.
$escapeCommand whether to escape the command passed to setCommand() or the constructor. This is only useful if $escapeArgs is false. Default is false.
$locale the locale to temporarily set before calling escapeshellargs(). Default is null for none.
$procCwd the initial working dir for proc_open(). Default is null for current PHP working dir.
$procEnv an array with environment variables to pass to proc_open(). Default is null for none.
$procOptions an array of other_options for proc_open(). Default is null for none.
$useExec 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.

보호된 프로퍼티들

프로퍼티 타입 설명
$_args the list of command arguments
$_command the command to execute
$_error the error message
$_execCommand the full command string to execute
$_executed whether the command was successfully executed
$_exitCode the exit code
$_stdErr the stderr output
$_stdOut the stdout output

공개 메소드들

메소드 설명
__construct ( string | array $options = null )
__toString ( ) : string
addArg ( string $key, string | array | null $value = null, boolean | null $escape = null ) : static
execute ( ) : boolean Execute the command
getArgs ( ) : string
getCommand ( ) : string | null
getError ( boolean $trim = true ) : string
getExecCommand ( ) : string | boolean
getExecuted ( ) : string
getExitCode ( ) : integer | null
getIsWindows ( ) : boolean
getOutput ( boolean $trim = true ) : string
getStdErr ( boolean $trim = true ) : string
setArgs ( string $args ) : static
setCommand ( string $command ) : static
setOptions ( array $options ) : static

메소드 상세

__construct() 공개 메소드

public __construct ( string | array $options = null )
$options string | array either a command string or an options array (see setOptions())

__toString() 공개 메소드

public __toString ( ) : string
리턴 string the current command string to execute

addArg() 공개 메소드

public addArg ( string $key, string | array | null $value = null, boolean | null $escape = null ) : static
$key string the argument key to add e.g. `--feature` or `--name=`. If the key does not end with and `=`, the $value will be separated by a space, if any. Keys are not escaped unless $value is null and $escape is `true`.
$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. `addArg('--exclude', array('val1','val2'))` which will create the option `--exclude 'val1' 'val2'`.
$escape boolean | null if set, this overrides the $escapeArgs setting and enforces escaping/no escaping
리턴 static for method chaining

execute() 공개 메소드

Execute the command
public execute ( ) : boolean
리턴 boolean whether execution was successful. If false, error details can be obtained through getError(), getStdErr() and getExitCode().

getArgs() 공개 메소드

public getArgs ( ) : string
리턴 string the command args that where set through setArgs() or added with addArg() separated by spaces

getCommand() 공개 메소드

public getCommand ( ) : string | null
리턴 string | null the command that was set through setCommand() or passed to the constructor. Null if none.

getError() 공개 메소드

public getError ( boolean $trim = true ) : string
$trim boolean whether to `trim()` the return value. The default is `true`.
리턴 string the error message, either stderr or internal message. Empty if none.

getExecCommand() 공개 메소드

public getExecCommand ( ) : string | boolean
리턴 string | boolean the full command string to execute. If no command was set with setCommand() or passed to the constructor it will return false.

getExecuted() 공개 메소드

public getExecuted ( ) : string
리턴 string whether the command was successfully executed

getExitCode() 공개 메소드

public getExitCode ( ) : integer | null
리턴 integer | null the exit code or null if command was not executed yet

getIsWindows() 공개 메소드

public getIsWindows ( ) : boolean
리턴 boolean whether we are on a Windows OS

getOutput() 공개 메소드

public getOutput ( boolean $trim = true ) : string
$trim boolean whether to `trim()` the return value. The default is `true`.
리턴 string the command output (stdout). Empty if none.

getStdErr() 공개 메소드

public getStdErr ( boolean $trim = true ) : string
$trim boolean whether to `trim()` the return value. The default is `true`.
리턴 string the stderr output. Empty if none.

setArgs() 공개 메소드

public setArgs ( string $args ) : static
$args string the command arguments as string. Note that these will not get escaped!
리턴 static for method chaining

setCommand() 공개 메소드

public setCommand ( string $command ) : static
$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 through escapeshellcmd().
리턴 static for method chaining

setOptions() 공개 메소드

public setOptions ( array $options ) : static
$options array array of name => value options that should be applied to the object You can also pass options that use a setter, e.g. you can pass a `fileName` option which will be passed to `setFileName()`.
리턴 static for method chaining

프로퍼티 상세

$_args 보호되어 있는 프로퍼티

the list of command arguments
protected $_args

$_command 보호되어 있는 프로퍼티

the command to execute
protected $_command

$_error 보호되어 있는 프로퍼티

the error message
protected $_error

$_execCommand 보호되어 있는 프로퍼티

the full command string to execute
protected $_execCommand

$_executed 보호되어 있는 프로퍼티

whether the command was successfully executed
protected $_executed

$_exitCode 보호되어 있는 프로퍼티

the exit code
protected $_exitCode

$_stdErr 보호되어 있는 프로퍼티

the stderr output
protected $_stdErr

$_stdOut 보호되어 있는 프로퍼티

the stdout output
protected $_stdOut

$captureStdErr 공개적으로 프로퍼티

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.
public $captureStdErr

$escapeArgs 공개적으로 프로퍼티

whether to escape any argument passed through addArg(). Default is true.
public $escapeArgs

$escapeCommand 공개적으로 프로퍼티

whether to escape the command passed to setCommand() or the constructor. This is only useful if $escapeArgs is false. Default is false.
public $escapeCommand

$locale 공개적으로 프로퍼티

the locale to temporarily set before calling escapeshellargs(). Default is null for none.
public $locale

$procCwd 공개적으로 프로퍼티

the initial working dir for proc_open(). Default is null for current PHP working dir.
public $procCwd

$procEnv 공개적으로 프로퍼티

an array with environment variables to pass to proc_open(). Default is null for none.
public $procEnv

$procOptions 공개적으로 프로퍼티

an array of other_options for proc_open(). Default is null for none.
public $procOptions

$useExec 공개적으로 프로퍼티

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.
public $useExec