PHP Класс Clinner\Command\Callback

This is a command abstraction which actually delegates the execution logic to a callback function. The function will be invoked with an input string argument, and is expected to return an integer value representing the exit code for the command: @param string|null $input The input for the string. @return int The exit code for the command. function callback(string $input); Any output generated to stdout will be buffered as the command's output. Usage examples: Get all the users in the system whose username contains at least one 'a' $systemUsers = Command::create('cat', array('/etc/passwd')) ->pipe( Command::create('grep', array('-v' => '^#'), array('delimiter' => ' ')) ) ->pipe( Command::create('cut', array('-d' => ':', '-f' => 1), array('delimiter' => '')) ) ->pipe($callbackCommand) ->run() ->getOutputAsArray("\n");
Автор: José Nahuel Cuesta Luengo ([email protected])
Наследование: implements Clinner\Command\CommandInterface, implements Clinner\Command\PipingCommandInterface, implements PipeableCommandInterface
Показать файл Открыть проект Примеры использования класса

Открытые методы

Метод Описание
__construct ( Closure $callback ) Constructor.
getCallback ( ) : Closure Get the callback function for this command.
getCallbackCode ( ) : string Get the code of the inner callback as string.
getErrorOutput ( ) : string Get the output for this command's execution.
getExitCode ( ) : integer Get the exit code for this command's execution.
getOutput ( ) : string Get the output for this command's execution.
getPipedCommand ( ) : Clinner\Command\PipeableCommandInterface Get the command piped to this one, if any.
hasPipedCommand ( ) : boolean Answer whether this command has a command piped to it.
pipe ( PipeableCommandInterface $anotherCommand, boolean $appendToPipe = true ) : Clinner\Command\PipingCommandInterface Pipe $anotherCommand to this one, so that this command's output is directly sent to $anotherCommand's standard input.
run ( string $input = null ) : Clinner\Command\CommandInterface Run this command and get the exit code for it.
setCallback ( Closure $callback ) : Callback Set the callback function for this command.
toCommandString ( ) : string Get a string representation of this command with its arguments, as if it would be written in a command-line interface when run.

Описание методов

__construct() публичный Метод

Constructor.
public __construct ( Closure $callback )
$callback Closure The callback function.

getCallback() публичный Метод

Get the callback function for this command.
public getCallback ( ) : Closure
Результат Closure

getCallbackCode() публичный Метод

Get the code of the inner callback as string.
public getCallbackCode ( ) : string
Результат string

getErrorOutput() публичный Метод

This method will only return a valid value after the command has been executed.
public getErrorOutput ( ) : string
Результат string

getExitCode() публичный Метод

This method will only return a valid value after the command has been executed.
public getExitCode ( ) : integer
Результат integer

getOutput() публичный Метод

This method will only return a valid value after the command has been executed.
public getOutput ( ) : string
Результат string

getPipedCommand() публичный Метод

Get the command piped to this one, if any.
public getPipedCommand ( ) : Clinner\Command\PipeableCommandInterface
Результат Clinner\Command\PipeableCommandInterface

hasPipedCommand() публичный Метод

Answer whether this command has a command piped to it.
public hasPipedCommand ( ) : boolean
Результат boolean

pipe() публичный Метод

Pipe $anotherCommand to this one, so that this command's output is directly sent to $anotherCommand's standard input.
public pipe ( PipeableCommandInterface $anotherCommand, boolean $appendToPipe = true ) : Clinner\Command\PipingCommandInterface
$anotherCommand PipeableCommandInterface The command to pipe.
$appendToPipe boolean Whether $anotherCommand will be appended to the currently piped commands (TRUE) or if it will be added after this command, rearranging the commands pipe to include it.
Результат Clinner\Command\PipingCommandInterface This instance, for a fluent API.

run() публичный Метод

Run this command and get the exit code for it.
public run ( string $input = null ) : Clinner\Command\CommandInterface
$input string (Optional) input string for this command.
Результат Clinner\Command\CommandInterface This command, for a fluent API.

setCallback() публичный Метод

Set the callback function for this command.
public setCallback ( Closure $callback ) : Callback
$callback Closure The callback function.
Результат Callback This instance, for a fluent API.

toCommandString() публичный Метод

Get a string representation of this command with its arguments, as if it would be written in a command-line interface when run.
public toCommandString ( ) : string
Результат string