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 (nahuelcuestaluengo@gmail.com)
Inheritance: implements Clinner\Command\CommandInterface, implements Clinner\Command\PipingCommandInterface, implements PipeableCommandInterface
Example #1
0
 public function testGetCallbackCode()
 {
     $closure = function () {
         echo 'Some nifty code';
     };
     $callback = new Callback($closure);
     $result = $callback->getCallbackCode();
     // Adding this ad-hoc regular expression to minimize the possible errors
     // that might occur while trying to match the source code string against an
     // expected value.
     $regexp = '#^\\s*function\\s*\\(\\s*\\)\\s*{\\s*echo\\s*\'Some nifty code\';\\s*}\\s*$#';
     $this->assertRegExp($regexp, $result);
 }