class FormatterHelper in Zircon Profile 8
Same name and namespace in other branches
- 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
- class \Symfony\Component\Console\Helper\Helper implements HelperInterface
- class \Symfony\Component\Console\Helper\FormatterHelper
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
File
- vendor/
symfony/ console/ Helper/ FormatterHelper.php, line 21
Namespace
Symfony\Component\Console\HelperView 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
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
FormatterHelper:: |
public | function | Formats a message as a block of text. | |
FormatterHelper:: |
public | function | Formats a message within a section. | |
FormatterHelper:: |
public | function |
Returns the canonical name of this helper. Overrides HelperInterface:: |
|
Helper:: |
protected | property | ||
Helper:: |
public static | function | ||
Helper:: |
public static | function | ||
Helper:: |
public | function |
Gets the helper set associated with this helper. Overrides HelperInterface:: |
|
Helper:: |
public | function |
Sets the helper set associated with this helper. Overrides HelperInterface:: |
|
Helper:: |
public static | function | Returns the length of a string, using mb_strwidth if it is available. | |
Helper:: |
public static | function |