Skip to content

Commit

Permalink
correct export progress bar to file
Browse files Browse the repository at this point in the history
  • Loading branch information
peter-gribanov committed Jun 23, 2017
1 parent 301cff5 commit 631b6f9
Showing 1 changed file with 42 additions and 0 deletions.
42 changes: 42 additions & 0 deletions src/Console/Progress/Export.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,16 @@ class Export extends PresetOutput
*/
protected $output;

/**
* @var int
*/
private $max = 0;

/**
* @var int
*/
private $current = 0;

/**
* @param ProgressHelper $progress
* @param OutputInterface $output
Expand All @@ -40,6 +50,38 @@ public function __construct(ProgressHelper $progress, OutputInterface $output, $
parent::__construct($progress, $output);
}

/**
* Starts the progress output.
*
* @param int|null $max Maximum steps
*/
public function start($max = null)
{
$this->max = (int) $max;
$this->progress->start($this->output, $max);
}

/**
* Advances the progress output X steps.
*
* @param int $step Number of steps to advance
* @param bool $redraw Whether to redraw or not
*
* @throws \LogicException
*/
public function advance($step = 1, $redraw = false)
{
parent::advance($step, $redraw);

$this->current += $step;

$percent = 0;
if ($this->max > 0) {
$percent = (float) $this->current / $this->max;
}
$this->output->write(sprintf('%d%%', floor($percent * 100)));
}

public function __destruct()
{
// say that scanning is completed
Expand Down

0 comments on commit 631b6f9

Please sign in to comment.