You are here

public function FormatterHelper::formatBlock in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 vendor/symfony/console/Helper/FormatterHelper.php \Symfony\Component\Console\Helper\FormatterHelper::formatBlock()

Formats a message as a block of text.

Parameters

string|array $messages The message to write in the block:

string $style The style to apply to the whole block:

bool $large Whether to return a large block:

Return value

string The formatter message

File

vendor/symfony/console/Helper/FormatterHelper.php, line 46

Class

FormatterHelper
The Formatter class provides helpers to format messages.

Namespace

Symfony\Component\Console\Helper

Code

public function formatBlock($messages, $style, $large = false) {
  if (!is_array($messages)) {
    $messages = array(
      $messages,
    );
  }
  $len = 0;
  $lines = array();
  foreach ($messages as $message) {
    $message = OutputFormatter::escape($message);
    $lines[] = sprintf($large ? '  %s  ' : ' %s ', $message);
    $len = max($this
      ->strlen($message) + ($large ? 4 : 2), $len);
  }
  $messages = $large ? array(
    str_repeat(' ', $len),
  ) : array();
  for ($i = 0; isset($lines[$i]); ++$i) {
    $messages[] = $lines[$i] . str_repeat(' ', $len - $this
      ->strlen($lines[$i]));
  }
  if ($large) {
    $messages[] = str_repeat(' ', $len);
  }
  for ($i = 0; isset($messages[$i]); ++$i) {
    $messages[$i] = sprintf('<%s>%s</%s>', $style, $messages[$i], $style);
  }
  return implode("\n", $messages);
}