我正在使用 Symfonie 的 Process 组件,我正在运行 git clone 命令并希望显示它的进度条到目前为止,我已经这样做了:
protected function cloneRepo(String $name)
{
$process = new Process(
"git clone {$this->getGitUrl(true)} {$name}" // does clone the repo works
);
$output = new ConsoleOutput();
// creates a new progress bar (100 units)
$progressBar = new ProgressBar($output, 100);
$process->run();
// starts and displays the progress bar
$progressBar->start();
$files = array_filter(explode("\n", $process->getOutput()), 'strlen');
for ($i = 0; $i < count($files); $i++) {
$progressBar->advance();
}
// ensures that the progress bar is at 100%
$progressBar->finish();
// executes after the command finishes
if (!$process->isSuccessful()) {
throw new ProcessFailedException($process);
}
echo $process->getOutput();
}
但这仅在克隆完成后显示完成的进度条