See also: ShellResult
Since: 1.0
Author: Paul Klimov (klimov.paul@gmail.com)
Example #1
0
 /**
  * Applies changes from remote repository.
  * @param string $projectRoot VCS project root directory path.
  * @param string $log if parameter passed it will be filled with related log string.
  * @return bool whether the changes have been applied successfully.
  */
 public function applyRemoteChanges($projectRoot, &$log = null)
 {
     $result = Shell::execute('(cd {projectRoot}; {binPath} merge {remote}/{branch})', ['{binPath}' => $this->binPath, '{projectRoot}' => $projectRoot, '{remote}' => $this->remoteName, '{branch}' => $this->getCurrentBranch($projectRoot)]);
     $log = $result->toString();
     return $result->isOk();
 }
 /**
  * Executes shell command.
  * @param string $command command text.
  * @return string command output.
  * @param array $placeholders placeholders to be replaced using `escapeshellarg()` in format: placeholder => value.
  * @throws Exception on failure.
  */
 protected function execShellCommand($command, array $placeholders = [])
 {
     $result = Shell::execute($command, $placeholders);
     $this->log($result->toString());
     $output = $result->getOutput();
     if (!$result->isOk()) {
         throw new Exception("Execution of '{$result->command}' failed: exit code = '{$result->exitCode}': \nOutput: \n{$output}");
     }
     foreach ($this->shellResponseErrorKeywords as $errorKeyword) {
         if (stripos($output, $errorKeyword) !== false) {
             throw new Exception("Execution of '{$result->command}' failed! \nOutput: \n{$output}");
         }
     }
     return $output;
 }