4 * This file is part of the Symfony package.
6 * (c) Fabien Potencier <fabien@symfony.com>
8 * For the full copyright and license information, please view the LICENSE
9 * file that was distributed with this source code.
12 namespace Symfony\Component\Console\Helper;
14 use Symfony\Component\Console\Formatter\OutputFormatter;
17 * The Formatter class provides helpers to format messages.
19 * @author Fabien Potencier <fabien@symfony.com>
21 class FormatterHelper extends Helper
24 * Formats a message within a section.
26 * @param string $section The section name
27 * @param string $message The message
28 * @param string $style The style to apply to the section
30 * @return string The format section
32 public function formatSection($section, $message, $style = 'info')
34 return sprintf('<%s>[%s]</%s> %s', $style, $section, $style, $message);
38 * Formats a message as a block of text.
40 * @param string|array $messages The message to write in the block
41 * @param string $style The style to apply to the whole block
42 * @param bool $large Whether to return a large block
44 * @return string The formatter message
46 public function formatBlock($messages, $style, $large = false)
48 if (!is_array($messages)) {
49 $messages = array($messages);
54 foreach ($messages as $message) {
55 $message = OutputFormatter::escape($message);
56 $lines[] = sprintf($large ? ' %s ' : ' %s ', $message);
57 $len = max($this->strlen($message) + ($large ? 4 : 2), $len);
60 $messages = $large ? array(str_repeat(' ', $len)) : array();
61 for ($i = 0; isset($lines[$i]); ++$i) {
62 $messages[] = $lines[$i].str_repeat(' ', $len - $this->strlen($lines[$i]));
65 $messages[] = str_repeat(' ', $len);
68 for ($i = 0; isset($messages[$i]); ++$i) {
69 $messages[$i] = sprintf('<%s>%s</%s>', $style, $messages[$i], $style);
72 return implode("\n", $messages);
78 public function getName()