OutputFormatter
in package
implements
WrappableOutputFormatterInterface
Formatter class for console output.
Tags
Table of Contents
Interfaces
- WrappableOutputFormatterInterface
- Formatter interface for console output that supports word wrapping.
Properties
- $decorated : mixed
- $styles : mixed
- $styleStack : mixed
Methods
- __clone() : mixed
- __construct() : mixed
- Initializes console output formatter.
- escape() : string
- Escapes "<" and ">" special chars in given text.
- format() : string
- Formats a message according to the given styles.
- formatAndWrap() : mixed
- Formats a message according to the given styles, wrapping at `$width` (0 means no wrapping).
- getStyle() : OutputFormatterStyleInterface
- Gets style options from style with specified name.
- getStyleStack() : OutputFormatterStyleStack
- hasStyle() : bool
- Checks if output formatter has style with specified name.
- isDecorated() : bool
- Gets the decorated flag.
- setDecorated() : mixed
- Sets the decorated flag.
- setStyle() : mixed
- Sets a new style.
- applyCurrentStyle() : string
- Applies current style from stack to text, if must be applied.
- createStyleFromString() : OutputFormatterStyleInterface|null
- Tries to create new style instance from string.
Properties
$decorated
private
mixed
$decorated
$styles
private
mixed
$styles
= []
$styleStack
private
mixed
$styleStack
Methods
__clone()
public
__clone() : mixed
__construct()
Initializes console output formatter.
public
__construct([bool $decorated = false ][, array<string|int, OutputFormatterStyleInterface> $styles = [] ]) : mixed
Parameters
- $decorated : bool = false
- $styles : array<string|int, OutputFormatterStyleInterface> = []
-
Array of "name => FormatterStyle" instances
escape()
Escapes "<" and ">" special chars in given text.
public
static escape(string $text) : string
Parameters
- $text : string
-
Text to escape
Return values
string —Escaped text
format()
Formats a message according to the given styles.
public
format(mixed $message) : string
Parameters
- $message : mixed
-
The message to style
Return values
string —The styled message
formatAndWrap()
Formats a message according to the given styles, wrapping at `$width` (0 means no wrapping).
public
formatAndWrap(string $message, int $width) : mixed
Parameters
- $message : string
- $width : int
getStyle()
Gets style options from style with specified name.
public
getStyle(mixed $name) : OutputFormatterStyleInterface
Parameters
- $name : mixed
Return values
OutputFormatterStyleInterfacegetStyleStack()
public
getStyleStack() : OutputFormatterStyleStack
Return values
OutputFormatterStyleStackhasStyle()
Checks if output formatter has style with specified name.
public
hasStyle(mixed $name) : bool
Parameters
- $name : mixed
Return values
boolisDecorated()
Gets the decorated flag.
public
isDecorated() : bool
Return values
bool —true if the output will decorate messages, false otherwise
setDecorated()
Sets the decorated flag.
public
setDecorated(mixed $decorated) : mixed
Parameters
- $decorated : mixed
-
Whether to decorate the messages or not
setStyle()
Sets a new style.
public
setStyle(mixed $name, OutputFormatterStyleInterface $style) : mixed
Parameters
- $name : mixed
-
The style name
- $style : OutputFormatterStyleInterface
applyCurrentStyle()
Applies current style from stack to text, if must be applied.
private
applyCurrentStyle(string $text, string $current, int $width, int &$currentLineLength) : string
Parameters
- $text : string
- $current : string
- $width : int
- $currentLineLength : int
Return values
stringcreateStyleFromString()
Tries to create new style instance from string.
private
createStyleFromString(string $string) : OutputFormatterStyleInterface|null
Parameters
- $string : string