PluginProbe
Depicter — Popup & Slider Builder / 1.3.2
Depicter — Popup & Slider Builder v1.3.2
4.8.1 trunk 1.0.0 1.1.0 1.1.2 1.1.4 1.1.6 1.1.7 1.1.8 1.1.9 1.2.0 1.3.0 1.3.1 1.3.2 1.3.3 1.3.5 1.3.8 1.5.0 1.5.1 1.5.2 1.5.5 1.6.0 1.6.1 1.6.2 1.7.0 All 76 releases
depicter / vendor / symfony / console / Helper / FormatterHelper.php

FormatterHelper.php in Depicter — Popup & Slider Builder 1.3.2, at vendor/symfony/console/Helper/FormatterHelper.php

93 lines 2.4 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
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
14 use Symfony\Component\Console\Formatter\OutputFormatter;
15
16 /**
17 * The Formatter class provides helpers to format messages.
18 *
19 * @author Fabien Potencier <fabien@symfony.com>
20 */
21 class FormatterHelper extends Helper
22 {
23 /**
24 * Formats a message within a section.
25 *
26 * @return string The format section
27 */
28 public function formatSection(string $section, string $message, string $style = 'info')
29 {
30 return sprintf('<%s>[%s]</%s> %s', $style, $section, $style, $message);
31 }
32
33 /**
34 * Formats a message as a block of text.
35 *
36 * @param string|array $messages The message to write in the block
37 *
38 * @return string The formatter message
39 */
40 public function formatBlock($messages, string $style, bool $large = false)
41 {
42 if (!\is_array($messages)) {
43 $messages = [$messages];
44 }
45
46 $len = 0;
47 $lines = [];
48 foreach ($messages as $message) {
49 $message = OutputFormatter::escape($message);
50 $lines[] = sprintf($large ? ' %s ' : ' %s ', $message);
51 $len = max(self::strlen($message) + ($large ? 4 : 2), $len);
52 }
53
54 $messages = $large ? [str_repeat(' ', $len)] : [];
55 for ($i = 0; isset($lines[$i]); ++$i) {
56 $messages[] = $lines[$i].str_repeat(' ', $len - self::strlen($lines[$i]));
57 }
58 if ($large) {
59 $messages[] = str_repeat(' ', $len);
60 }
61
62 for ($i = 0; isset($messages[$i]); ++$i) {
63 $messages[$i] = sprintf('<%s>%s</%s>', $style, $messages[$i], $style);
64 }
65
66 return implode("\n", $messages);
67 }
68
69 /**
70 * Truncates a message to the given length.
71 *
72 * @return string
73 */
74 public function truncate(string $message, int $length, string $suffix = '...')
75 {
76 $computedLength = $length - self::strlen($suffix);
77
78 if ($computedLength > self::strlen($message)) {
79 return $message;
80 }
81
82 return self::substr($message, 0, $length).$suffix;
83 }
84
85 /**
86 * {@inheritdoc}
87 */
88 public function getName()
89 {
90 return 'formatter';
91 }
92 }
93