PHP Class 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");
Author: José Nahuel Cuesta Luengo ([email protected])
Inheritance: implements Clinner\Command\CommandInterface, implements Clinner\Command\PipingCommandInterface, implements PipeableCommandInterface
Show file Open project: ncuesta/clinner Class Usage Examples

Public Methods

Method Description
__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.

Method Details

__construct() public method

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

getCallback() public method

Get the callback function for this command.
public getCallback ( ) : Closure
return Closure

getCallbackCode() public method

Get the code of the inner callback as string.
public getCallbackCode ( ) : string
return string

getErrorOutput() public method

This method will only return a valid value after the command has been executed.
public getErrorOutput ( ) : string
return string

getExitCode() public method

This method will only return a valid value after the command has been executed.
public getExitCode ( ) : integer
return integer

getOutput() public method

This method will only return a valid value after the command has been executed.
public getOutput ( ) : string
return string

getPipedCommand() public method

Get the command piped to this one, if any.
public getPipedCommand ( ) : Clinner\Command\PipeableCommandInterface
return Clinner\Command\PipeableCommandInterface

hasPipedCommand() public method

Answer whether this command has a command piped to it.
public hasPipedCommand ( ) : boolean
return boolean

pipe() public method

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.
return Clinner\Command\PipingCommandInterface This instance, for a fluent API.

run() public method

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.
return Clinner\Command\CommandInterface This command, for a fluent API.

setCallback() public method

Set the callback function for this command.
public setCallback ( Closure $callback ) : Callback
$callback Closure The callback function.
return Callback This instance, for a fluent API.

toCommandString() public method

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
return string