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

initPlaceholderFormatters() private static method

private static initPlaceholderFormatters ( )
    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);
        });
    }