think\Console::run PHP Method

run() public method

执行当前的指令
public run ( ) : integer
return integer
    public function run()
    {
        $input = new Input();
        $output = new Output();
        $this->configureIO($input, $output);
        try {
            $exitCode = $this->doRun($input, $output);
        } catch (\Exception $e) {
            if (!$this->catchExceptions) {
                throw $e;
            }
            $output->renderException($e);
            $exitCode = $e->getCode();
            if (is_numeric($exitCode)) {
                $exitCode = (int) $exitCode;
                if (0 === $exitCode) {
                    $exitCode = 1;
                }
            } else {
                $exitCode = 1;
            }
        }
        if ($this->autoExit) {
            if ($exitCode > 255) {
                $exitCode = 255;
            }
            exit($exitCode);
        }
        return $exitCode;
    }

Usage Example

Exemplo n.º 1
0
 /**
  * 执行应用程序
  * @access public
  * @return void
  */
 public static function run()
 {
     self::init();
     // 实例化console
     $console = new Console('Think Console', '0.1');
     // 读取指令集
     if (is_file(APP_PATH . 'command' . EXT)) {
         $commands = (include APP_PATH . 'command' . EXT);
         if (is_array($commands)) {
             foreach ($commands as $command) {
                 if (class_exists($command) && is_subclass_of($command, "\\think\\console\\command\\Command")) {
                     // 注册指令
                     $console->add(new $command());
                 }
             }
         }
     }
     // 运行
     $console->run();
 }