Clinner\Command\Callback::run PHP Метод

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.
    public function run($input = null)
    {
        $callback = $this->getCallback();
        ob_start();
        $exitCode = $callback($input);
        $output = ob_get_contents();
        ob_end_clean();
        // Run the piped command, if any
        if ($this->hasPipedCommand()) {
            $pipedCommand = $this->getPipedCommand();
            $pipedCommand->run($output);
            $output = $pipedCommand->getOutput();
            $exitCode = $pipedCommand->getExitCode();
            $errorOutput = $pipedCommand->getErrorOutput();
        }
        $this->_output = $output;
        $this->_exitCode = $exitCode;
        return $this;
    }

Usage Example

Пример #1
0
 /**
  * @depends testRun
  */
 public function testGetErrorOutput()
 {
     $closure = function () {
         echo 'Do nothing';
     };
     $callback = new Callback($closure);
     // Output must be null before the command is run
     $this->assertNull($callback->getErrorOutput());
     $callback->run();
     // Output must remain null after the command is run with the given $closure
     $this->assertNull($callback->getErrorOutput());
 }