Skip to main content
Drupal API
User account menu
  • Log in

Breadcrumb

  1. Drupal Core 11.1.x
  2. ProgressBar.php

function 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, globally for all instances of ProgressBar.

File

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

Class

ProgressBar
The ProgressBar provides helpers to display progress output.

Namespace

Symfony\Component\Console\Helper

Code

private static function initPlaceholderFormatters() : array {
    return [
        'bar' => function (self $bar, OutputInterface $output) {
            $completeBars = $bar->getBarOffset();
            $display = str_repeat($bar->getBarCharacter(), $completeBars);
            if ($completeBars < $bar->getBarWidth()) {
                $emptyBars = $bar->getBarWidth() - $completeBars - Helper::length(Helper::removeDecoration($output->getFormatter(), $bar->getProgressCharacter()));
                $display .= $bar->getProgressCharacter() . str_repeat($bar->getEmptyBarCharacter(), $emptyBars);
            }
            return $display;
        },
        'elapsed' => fn(self $bar) => Helper::formatTime(time() - $bar->getStartTime(), 2),
        'remaining' => function (self $bar) {
            if (null === $bar->getMaxSteps()) {
                throw new LogicException('Unable to display the remaining time if the maximum number of steps is not set.');
            }
            return Helper::formatTime($bar->getRemaining(), 2);
        },
        'estimated' => function (self $bar) {
            if (null === $bar->getMaxSteps()) {
                throw new LogicException('Unable to display the estimated time if the maximum number of steps is not set.');
            }
            return Helper::formatTime($bar->getEstimated(), 2);
        },
        'memory' => fn(self $bar) => Helper::formatMemory(memory_get_usage(true)),
        'current' => fn(self $bar) => str_pad($bar->getProgress(), $bar->getStepWidth(), ' ', \STR_PAD_LEFT),
        'max' => fn(self $bar) => $bar->getMaxSteps(),
        'percent' => fn(self $bar) => floor($bar->getProgressPercent() * 100),
    ];
}

API Navigation

  • Drupal Core 11.1.x
  • Topics
  • Classes
  • Functions
  • Constants
  • Globals
  • Files
  • Namespaces
  • Deprecated
  • Services
RSS feed
Powered by Drupal