think\console\Command::run PHP Method

run() public method

执行
See also: setCode()
See also: execute()
public run ( Input $input, Output $output ) : integer
$input Input
$output Output
return integer
    public function run(Input $input, Output $output)
    {
        $this->input = $input;
        $this->output = $output;
        $this->getSynopsis(true);
        $this->getSynopsis(false);
        $this->mergeConsoleDefinition();
        try {
            $input->bind($this->definition);
        } catch (\Exception $e) {
            if (!$this->ignoreValidationErrors) {
                throw $e;
            }
        }
        $this->initialize($input, $output);
        if ($input->isInteractive()) {
            $this->interact($input, $output);
        }
        $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

Exemplo n.º 1
0
 /**
  * 执行指令
  * @param Command $command 指令实例
  * @param Input   $input   输入实例
  * @param Output  $output  输出实例
  * @return int
  * @throws \Exception
  */
 protected function doRunCommand(Command $command, Input $input, Output $output)
 {
     return $command->run($input, $output);
 }