You are here

private static function ProgressBar::initPlaceholderFormatters in Zircon Profile 8.0

Same name and namespace in other branches
  1. 8 vendor/symfony/console/Helper/ProgressBar.php \Symfony\Component\Console\Helper\ProgressBar::initPlaceholderFormatters()
2 calls to ProgressBar::initPlaceholderFormatters()
ProgressBar::getPlaceholderFormatterDefinition in vendor/symfony/console/Helper/ProgressBar.php
Gets the placeholder formatter for a given name.
ProgressBar::setPlaceholderFormatterDefinition in vendor/symfony/console/Helper/ProgressBar.php
Sets a placeholder formatter for a given name.

File

vendor/symfony/console/Helper/ProgressBar.php, line 565

Class

ProgressBar
The ProgressBar provides helpers to display progress output.

Namespace

Symfony\Component\Console\Helper

Code

private static function initPlaceholderFormatters() {
  return array(
    'bar' => function (ProgressBar $bar, OutputInterface $output) {
      $completeBars = floor($bar
        ->getMaxSteps() > 0 ? $bar
        ->getProgressPercent() * $bar
        ->getBarWidth() : $bar
        ->getProgress() % $bar
        ->getBarWidth());
      $display = str_repeat($bar
        ->getBarCharacter(), $completeBars);
      if ($completeBars < $bar
        ->getBarWidth()) {
        $emptyBars = $bar
          ->getBarWidth() - $completeBars - Helper::strlenWithoutDecoration($output
          ->getFormatter(), $bar
          ->getProgressCharacter());
        $display .= $bar
          ->getProgressCharacter() . str_repeat($bar
          ->getEmptyBarCharacter(), $emptyBars);
      }
      return $display;
    },
    'elapsed' => function (ProgressBar $bar) {
      return Helper::formatTime(time() - $bar
        ->getStartTime());
    },
    'remaining' => function (ProgressBar $bar) {
      if (!$bar
        ->getMaxSteps()) {
        throw new \LogicException('Unable to display the remaining time if the maximum number of steps is not set.');
      }
      if (!$bar
        ->getProgress()) {
        $remaining = 0;
      }
      else {
        $remaining = round((time() - $bar
          ->getStartTime()) / $bar
          ->getProgress() * ($bar
          ->getMaxSteps() - $bar
          ->getProgress()));
      }
      return Helper::formatTime($remaining);
    },
    'estimated' => function (ProgressBar $bar) {
      if (!$bar
        ->getMaxSteps()) {
        throw new \LogicException('Unable to display the estimated time if the maximum number of steps is not set.');
      }
      if (!$bar
        ->getProgress()) {
        $estimated = 0;
      }
      else {
        $estimated = round((time() - $bar
          ->getStartTime()) / $bar
          ->getProgress() * $bar
          ->getMaxSteps());
      }
      return Helper::formatTime($estimated);
    },
    'memory' => function (ProgressBar $bar) {
      return Helper::formatMemory(memory_get_usage(true));
    },
    'current' => function (ProgressBar $bar) {
      return str_pad($bar
        ->getProgress(), $bar
        ->getStepWidth(), ' ', STR_PAD_LEFT);
    },
    'max' => function (ProgressBar $bar) {
      return $bar
        ->getMaxSteps();
    },
    'percent' => function (ProgressBar $bar) {
      return floor($bar
        ->getProgressPercent() * 100);
    },
  );
}