TYPO3  7.6
FormatterHelper.php
Go to the documentation of this file.
1 <?php
2 
3 /*
4  * This file is part of the Symfony package.
5  *
6  * (c) Fabien Potencier <fabien@symfony.com>
7  *
8  * For the full copyright and license information, please view the LICENSE
9  * file that was distributed with this source code.
10  */
11 
12 namespace Symfony\Component\Console\Helper;
13 
15 
21 class FormatterHelper extends Helper
22 {
32  public function formatSection($section, $message, $style = 'info')
33  {
34  return sprintf('<%s>[%s]</%s> %s', $style, $section, $style, $message);
35  }
36 
46  public function formatBlock($messages, $style, $large = false)
47  {
48  if (!is_array($messages)) {
49  $messages = array($messages);
50  }
51 
52  $len = 0;
53  $lines = array();
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);
58  }
59 
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]));
63  }
64  if ($large) {
65  $messages[] = str_repeat(' ', $len);
66  }
67 
68  for ($i = 0; isset($messages[$i]); ++$i) {
69  $messages[$i] = sprintf('<%s>%s</%s>', $style, $messages[$i], $style);
70  }
71 
72  return implode("\n", $messages);
73  }
74 
78  public function getName()
79  {
80  return 'formatter';
81  }
82 }