[ Index ] |
PHP Cross Reference of Joomla 4.2.2 documentation |
[Summary view] [Print] [Text view]
1 <?php 2 3 /* 4 * This file is part of the Symfony package. 5 * 6 * (c) Fabien Potencier <[email protected]> 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 <[email protected]> 20 */ 21 class FormatterHelper extends Helper 22 { 23 /** 24 * Formats a message within a section. 25 * 26 * @return string 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 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::width($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::width($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::width($suffix); 77 78 if ($computedLength > self::width($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 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Wed Sep 7 05:41:13 2022 | Chilli.vc Blog - For Webmaster,Blog-Writer,System Admin and Domainer |