Webmozart\Console\ConsoleApplication::run PHP Method

run() public method

public run ( Webmozart\Console\Api\Args\RawArgs $args = null, Webmozart\Console\Api\IO\InputStream $inputStream = null, Webmozart\Console\Api\IO\OutputStream $outputStream = null, Webmozart\Console\Api\IO\OutputStream $errorStream = null )
$args Webmozart\Console\Api\Args\RawArgs
$inputStream Webmozart\Console\Api\IO\InputStream
$outputStream Webmozart\Console\Api\IO\OutputStream
$errorStream Webmozart\Console\Api\IO\OutputStream
    public function run(RawArgs $args = null, InputStream $inputStream = null, OutputStream $outputStream = null, OutputStream $errorStream = null)
    {
        // Render errors to the preliminary IO until the final IO is created
        $io = $this->preliminaryIo;
        try {
            if (null === $args) {
                $args = new ArgvArgs();
            }
            $ioFactory = $this->config->getIOFactory();
            if (null === $ioFactory) {
                throw new LogicException('The IO factory must be set.');
            }
            /** @var IO $io */
            $io = call_user_func($ioFactory, $this, $args, $inputStream, $outputStream, $errorStream);
            $resolvedCommand = $this->resolveCommand($args);
            $command = $resolvedCommand->getCommand();
            $parsedArgs = $resolvedCommand->getArgs();
            $statusCode = $command->handle($parsedArgs, $io);
        } catch (Exception $e) {
            if (!$this->config->isExceptionCaught()) {
                throw $e;
            }
            $trace = new ExceptionTrace($e);
            $trace->render($io);
            $statusCode = $this->exceptionToExitCode($e->getCode());
        }
        if ($this->config->isTerminatedAfterRun()) {
            exit($statusCode);
        }
        return $statusCode;
    }

Usage Example

 /**
  * @expectedException \Webmozart\Console\Api\Command\NoSuchCommandException
  */
 public function testThrowExceptionIfCatchingNotActive()
 {
     $this->config->setCatchExceptions(false)->beginCommand('list')->setHandler(new CallbackHandler(function () {
         throw NoSuchCommandException::forCommandName('foobar', 123);
     }))->end();
     $args = new StringArgs('list');
     $input = new StringInputStream();
     $output = new BufferedOutputStream();
     $errorOutput = new BufferedOutputStream();
     $application = new ConsoleApplication($this->config);
     $application->run($args, $input, $output, $errorOutput);
 }
All Usage Examples Of Webmozart\Console\ConsoleApplication::run