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 : bool
- $styles : array<string|int, mixed>
- $styleStack : OutputFormatterStyleStack
Methods
- __clone() : mixed
- __construct() : mixed
- Initializes console output formatter.
- escape() : string
- Escapes "<" and ">" special chars in given text.
- format() : string|null
- Formats a message according to the given styles.
- formatAndWrap() : string
- 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
- Whether the output will decorate messages.
- setDecorated() : void
- Sets the decorated flag.
- setStyle() : void
- Sets a new style.
- addLineBreaks() : string
- 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
bool
$decorated
$styles
private
array<string|int, mixed>
$styles
= []
$styleStack
private
OutputFormatterStyleStack
$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
Return values
stringformat()
Formats a message according to the given styles.
public
format(string|null $message) : string|null
Parameters
- $message : string|null
Return values
string|nullformatAndWrap()
Formats a message according to the given styles, wrapping at `$width` (0 means no wrapping).
public
formatAndWrap(string|null $message, int $width) : string
Parameters
- $message : string|null
- $width : int
Return values
stringgetStyle()
Gets style options from style with specified name.
public
getStyle(string $name) : OutputFormatterStyleInterface
Parameters
- $name : string
Return values
OutputFormatterStyleInterfacegetStyleStack()
public
getStyleStack() : OutputFormatterStyleStack
Return values
OutputFormatterStyleStackhasStyle()
Checks if output formatter has style with specified name.
public
hasStyle(string $name) : bool
Parameters
- $name : string
Return values
boolisDecorated()
Whether the output will decorate messages.
public
isDecorated() : bool
Return values
boolsetDecorated()
Sets the decorated flag.
public
setDecorated(bool $decorated) : void
Parameters
- $decorated : bool
setStyle()
Sets a new style.
public
setStyle(string $name, OutputFormatterStyleInterface $style) : void
Parameters
- $name : string
- $style : OutputFormatterStyleInterface
addLineBreaks()
private
addLineBreaks(string $text, int $width) : string
Parameters
- $text : string
- $width : int
Return values
stringapplyCurrentStyle()
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