You are here

class FormatterHelper 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

The Formatter class provides helpers to format messages.

@author Fabien Potencier <fabien@symfony.com>

Hierarchy

Expanded class hierarchy of FormatterHelper

6 files declare their use of FormatterHelper
Application.php in vendor/symfony/console/Application.php
ApplicationTest.php in vendor/symfony/console/Tests/ApplicationTest.php
CommandTest.php in vendor/symfony/console/Tests/Command/CommandTest.php
FormatterHelperTest.php in vendor/symfony/console/Tests/Helper/FormatterHelperTest.php
LegacyDialogHelperTest.php in vendor/symfony/console/Tests/Helper/LegacyDialogHelperTest.php

... See full list

File

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

Namespace

Symfony\Component\Console\Helper
View source
class FormatterHelper extends Helper {

  /**
   * Formats a message within a section.
   *
   * @param string $section The section name
   * @param string $message The message
   * @param string $style   The style to apply to the section
   *
   * @return string The format section
   */
  public function formatSection($section, $message, $style = 'info') {
    return sprintf('<%s>[%s]</%s> %s', $style, $section, $style, $message);
  }

  /**
   * Formats a message as a block of text.
   *
   * @param string|array $messages The message to write in the block
   * @param string       $style    The style to apply to the whole block
   * @param bool         $large    Whether to return a large block
   *
   * @return string The formatter message
   */
  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);
  }

  /**
   * {@inheritdoc}
   */
  public function getName() {
    return 'formatter';
  }

}

Members

Namesort descending Modifiers Type Description Overrides
FormatterHelper::formatBlock public function Formats a message as a block of text.
FormatterHelper::formatSection public function Formats a message within a section.
FormatterHelper::getName public function Returns the canonical name of this helper. Overrides HelperInterface::getName
Helper::$helperSet protected property
Helper::formatMemory public static function
Helper::formatTime public static function
Helper::getHelperSet public function Gets the helper set associated with this helper. Overrides HelperInterface::getHelperSet
Helper::setHelperSet public function Sets the helper set associated with this helper. Overrides HelperInterface::setHelperSet
Helper::strlen public static function Returns the length of a string, using mb_strwidth if it is available.
Helper::strlenWithoutDecoration public static function