Symfony\Component\Console\Helper\ProgressBar::setProgress PHP Method

setProgress() public method

Sets the current progress.
public setProgress ( integer $step )
$step integer The current progress
    public function setProgress($step)
    {
        $step = (int) $step;
        if ($this->max && $step > $this->max) {
            $this->max = $step;
        } elseif ($step < 0) {
            $step = 0;
        }
        $prevPeriod = (int) ($this->step / $this->redrawFreq);
        $currPeriod = (int) ($step / $this->redrawFreq);
        $this->step = $step;
        $this->percent = $this->max ? (double) $this->step / $this->max : 0;
        if ($prevPeriod !== $currPeriod || $this->max === $step) {
            $this->display();
        }
    }

Usage Example

コード例 #1
0
 /**
  * @return bool
  */
 public function download()
 {
     if ($this->isDownloaded()) {
         return true;
     }
     $httpClient = new Client();
     $request = new Request('GET', $this->getUrl());
     $response = $httpClient->send($request, [RequestOptions::PROGRESS => function ($total, $current) {
         if ($total <= 0 || !$this->output) {
             return;
         }
         if (!$this->progressBar) {
             $this->progressBar = new ProgressBar($this->output, $total);
             $this->progressBar->setPlaceholderFormatterDefinition('max', function (ProgressBar $bar) {
                 return $this->formatSize($bar->getMaxSteps());
             });
             $this->progressBar->setPlaceholderFormatterDefinition('current', function (ProgressBar $bar) {
                 return str_pad($this->formatSize($bar->getProgress()), 11, ' ', STR_PAD_LEFT);
             });
         }
         $this->progressBar->setProgress($current);
     }]);
     $this->filesystem->dumpFile($this->getDestinationFile(), $response->getBody()->getContents());
     $this->downloaded = true;
     return true;
 }
All Usage Examples Of Symfony\Component\Console\Helper\ProgressBar::setProgress