getIO() public method

Returns the I/O.
public getIO ( ) : IO
return Webmozart\Console\Api\IO\IO The I/O.
 public function initApplication(PreHandleEvent $event)
 {
     if (null !== $this->app) {
         return;
     }
     try {
         $this->app = new Jarvis($this->settings);
     } catch (\Exception $e) {
         $event->getIO()->writeLine("<error>{$e->getMessage()}</error>");
         exit(1);
     }
 }
 /**
  * @param PreHandleEvent $event
  */
 public function printVersion(PreHandleEvent $event)
 {
     if ($event->getArgs()->isOptionSet('version')) {
         $version = new NameVersion($event->getCommand()->getApplication()->getConfig());
         $version->render($event->getIO());
         $event->setHandled(true);
     }
 }
Esempio n. 3
0
 /**
  * @param PreHandleEvent $event
  */
 protected function onPreHandle(PreHandleEvent $event)
 {
     // convert console args to command
     $this->commandConverter->setArgs($event->getArgs());
     $this->commandConverter->setFormat($event->getCommand()->getArgsFormat());
     /** @var CommandConfig $commandConfig */
     $commandConfig = $event->getCommand()->getConfig();
     if ($event->getCommand()->getName() !== 'help') {
         if ($commandConfig->className() === null && count($commandConfig->getSubCommandConfigs()) === 0) {
             throw new \RuntimeException(sprintf('The command %s definition must set the className using ->setClass() method', $event->getCommand()->getName()));
         }
     }
     $command = $this->commandConverter->getCommandFrom($commandConfig->className());
     $this->defaultHandler->setIo($event->getIO());
     $this->defaultHandler->clearEventHandlers();
     if ($commandConfig->preDispatchEventHandler() !== null) {
         $this->defaultHandler->addPreDispatchEventHandler($commandConfig->preDispatchEventHandler());
     }
     if ($commandConfig->postDispatchEventHandler()) {
         $this->defaultHandler->addPostDispatchEventHandler($commandConfig->postDispatchEventHandler());
     }
     $commandConfig->setEventBus($this->eventBus);
     $commandConfig->addEventSubscriber($this->defaultHandler);
     if ($command !== null) {
         if ($command instanceof ConsoleCommandInterface) {
             $command->setIo($event->getIO());
         }
         try {
             $this->commandBus->dispatch($command);
             $event->setHandled(true);
             $event->setStatusCode(0);
         } catch (NotFoundException $e) {
         }
     } else {
         if ($event->getCommand()->getName() !== 'help') {
             $helpCommand = $this->getCommand('help');
             $args = $event->getArgs();
             $args = $helpCommand->parseArgs($args->getRawArgs());
             $args->setArgument('command', $event->getCommand()->getName());
             $helpConfig = $this->getConfig()->getCommandConfig('help');
             $commandHandler = $helpConfig->getHandler();
             $handlerMethod = $helpConfig->getHandlerMethod();
             $commandHandler->{$handlerMethod}($args, $event->getIO(), $helpCommand);
             $event->setHandled(true);
             $event->setStatusCode(0);
         }
     }
 }