Symfony\Component\Console\Command\Command::run PHP Method

run() public method

The code to execute is either defined directly with the setCode() method or by overriding the execute() method in a sub-class.
See also: setCode()
See also: execute()
public run ( Symfony\Component\Console\Input\InputInterface $input, Symfony\Component\Console\Output\OutputInterface $output ) : integer
$input Symfony\Component\Console\Input\InputInterface An InputInterface instance
$output Symfony\Component\Console\Output\OutputInterface An OutputInterface instance
return integer The command exit code
    public function run(InputInterface $input, OutputInterface $output)
    {
        // force the creation of the synopsis before the merge with the app definition
        $this->getSynopsis(true);
        $this->getSynopsis(false);
        // add the application arguments and options
        $this->mergeApplicationDefinition();
        // bind the input against the command specific arguments/options
        try {
            $input->bind($this->definition);
        } catch (ExceptionInterface $e) {
            if (!$this->ignoreValidationErrors) {
                throw $e;
            }
        }
        $this->initialize($input, $output);
        if (null !== $this->processTitle) {
            if (function_exists('cli_set_process_title')) {
                cli_set_process_title($this->processTitle);
            } elseif (function_exists('setproctitle')) {
                setproctitle($this->processTitle);
            } elseif (OutputInterface::VERBOSITY_VERY_VERBOSE === $output->getVerbosity()) {
                $output->writeln('<comment>Install the proctitle PECL to be able to change the process title.</comment>');
            }
        }
        if ($input->isInteractive()) {
            $this->interact($input, $output);
        }
        // The command name argument is often omitted when a command is executed directly with its run() method.
        // It would fail the validation if we didn't make sure the command argument is present,
        // since it's required by the application.
        if ($input->hasArgument('command') && null === $input->getArgument('command')) {
            $input->setArgument('command', $this->getName());
        }
        $input->validate();
        if ($this->code) {
            $statusCode = call_user_func($this->code, $input, $output);
        } else {
            $statusCode = $this->execute($input, $output);
        }
        return is_numeric($statusCode) ? (int) $statusCode : 0;
    }

Usage Example

 /**
  * Perform the actual check and return a ResultInterface
  *
  * @return ResultInterface
  * @throws \Exception
  */
 public function check()
 {
     $exitCode = $this->command->run($this->input, $this->output);
     $data = [];
     if ($this->output instanceof PropertyOutput) {
         $data = $this->output->getMessage();
         if (!is_array($data)) {
             $data = explode(PHP_EOL, trim($data));
         }
     }
     if ($exitCode < 1) {
         return new Success(get_class($this->command), $data);
     }
     return new Failure(get_class($this->command), $data);
 }
All Usage Examples Of Symfony\Component\Console\Command\Command::run