You are here

public function SymfonyStyle::block in Zircon Profile 8.0

Same name and namespace in other branches
  1. 8 vendor/symfony/console/Style/SymfonyStyle.php \Symfony\Component\Console\Style\SymfonyStyle::block()

Formats a message as a block of text.

Parameters

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

string|null $type The block type (added in [] on first line):

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

string $prefix The prefix for the block:

bool $padding Whether to add vertical padding:

5 calls to SymfonyStyle::block()
SymfonyStyle::caution in vendor/symfony/console/Style/SymfonyStyle.php
Formats a caution admonition.
SymfonyStyle::error in vendor/symfony/console/Style/SymfonyStyle.php
Formats an error result bar.
SymfonyStyle::note in vendor/symfony/console/Style/SymfonyStyle.php
Formats a note admonition.
SymfonyStyle::success in vendor/symfony/console/Style/SymfonyStyle.php
Formats a success result bar.
SymfonyStyle::warning in vendor/symfony/console/Style/SymfonyStyle.php
Formats an warning result bar.

File

vendor/symfony/console/Style/SymfonyStyle.php, line 65

Class

SymfonyStyle
Output decorator helpers for the Symfony Style Guide.

Namespace

Symfony\Component\Console\Style

Code

public function block($messages, $type = null, $style = null, $prefix = ' ', $padding = false) {
  $this
    ->autoPrependBlock();
  $messages = is_array($messages) ? array_values($messages) : array(
    $messages,
  );
  $lines = array();

  // add type
  if (null !== $type) {
    $messages[0] = sprintf('[%s] %s', $type, $messages[0]);
  }

  // wrap and add newlines for each element
  foreach ($messages as $key => $message) {
    $message = OutputFormatter::escape($message);
    $lines = array_merge($lines, explode(PHP_EOL, wordwrap($message, $this->lineLength - Helper::strlen($prefix), PHP_EOL, true)));
    if (count($messages) > 1 && $key < count($messages) - 1) {
      $lines[] = '';
    }
  }
  if ($padding && $this
    ->isDecorated()) {
    array_unshift($lines, '');
    $lines[] = '';
  }
  foreach ($lines as &$line) {
    $line = sprintf('%s%s', $prefix, $line);
    $line .= str_repeat(' ', $this->lineLength - Helper::strlenWithoutDecoration($this
      ->getFormatter(), $line));
    if ($style) {
      $line = sprintf('<%s>%s</>', $style, $line);
    }
  }
  $this
    ->writeln($lines);
  $this
    ->newLine();
}