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

Breadcrumb

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

function ProgressBar::buildLine

1 call to ProgressBar::buildLine()
ProgressBar::display in vendor/symfony/console/Helper/ProgressBar.php
Outputs the current progress string.

File

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

Class

ProgressBar
The ProgressBar provides helpers to display progress output.

Namespace

Symfony\Component\Console\Helper

Code

private function buildLine() : string {
    \assert(null !== $this->format);
    $regex = '{%([a-z\\-_]+)(?:\\:([^%]+))?%}i';
    $callback = function ($matches) {
        if ($formatter = $this->getPlaceholderFormatter($matches[1])) {
            $text = $formatter($this, $this->output);
        }
        elseif (isset($this->messages[$matches[1]])) {
            $text = $this->messages[$matches[1]];
        }
        else {
            return $matches[0];
        }
        if (isset($matches[2])) {
            $text = \sprintf('%' . $matches[2], $text);
        }
        return $text;
    };
    $line = preg_replace_callback($regex, $callback, $this->format);
    // gets string length for each sub line with multiline format
    $linesLength = array_map(fn($subLine) => Helper::width(Helper::removeDecoration($this->output
        ->getFormatter(), rtrim($subLine, "\r"))), explode("\n", $line));
    $linesWidth = max($linesLength);
    $terminalWidth = $this->terminal
        ->getWidth();
    if ($linesWidth <= $terminalWidth) {
        return $line;
    }
    $this->setBarWidth($this->barWidth - $linesWidth + $terminalWidth);
    return preg_replace_callback($regex, $callback, $this->format);
}

API Navigation

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