setStatusCode() public method

This method is only useful in combination with {@link setHandled()}. If the event is not marked as handled, the status code is ignored.
public setStatusCode ( integer $statusCode )
$statusCode integer Set to 0 on success and any positive integer on error.
Esempio n. 1
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);
         }
     }
 }