app\components\Command::runLocalCommand PHP Method

runLocalCommand() final public method

执行本地宿主机命令
final public runLocalCommand ( $command ) : boolean | integer
$command
return boolean | integer true 成功,false 失败
    public final function runLocalCommand($command)
    {
        $command = trim($command);
        $this->log('---------------------------------');
        $this->log('---- Executing: $ ' . $command);
        $status = 1;
        $log = '';
        exec($command . ' 2>&1', $log, $status);
        // 执行过的命令
        $this->command = $command;
        // 执行的状态
        $this->status = !$status;
        // 操作日志
        $log = implode(PHP_EOL, $log);
        $this->log = trim($log);
        $this->log($log);
        $this->log('---------------------------------');
        return $this->status;
    }

Usage Example

Example #1
0
 /**
  * upgrade walle 更新walle版本
  *
  * @throws yii\console\Exception
  */
 public function actionUpgrade()
 {
     $commander = new Command(['console']);
     // stash save local change 暂存本地修改
     echo 'stash save local change 暂存本地修改: git stash save ...', PHP_EOL;
     $commander->runLocalCommand('/usr/bin/env git stash save');
     // pull code 更新代码
     echo 'pull code 更新代码: git pull ...', PHP_EOL;
     $commander->runLocalCommand('/usr/bin/env git pull');
     // stash pop local change 弹出暂存本地修改
     echo 'stash pop local change 弹出暂存本地修改: git stash pop ...', PHP_EOL;
     $commander->runLocalCommand('/usr/bin/env git stash pop');
     // init walle 初始化项目
     $this->runAction('setup', ['interactive' => $this->interactive]);
     // checkout the current version查看最新版本
     echo "\n--------------------------------------------------------", PHP_EOL;
     echo "Congratulations To Upgrade. Your Walle Current Version:", PHP_EOL;
     $this->runAction('index', ['interactive' => $this->interactive]);
 }