Formatter
class Formatter implements FormatterInterface
Formatter.
Constants
TAG_REGEX |
Regex that matches non-escaped tags. |
ESCAPED_TAG_REGEX |
Regex that matches escaped tags. |
ANSI_SGR_SEQUENCE_REGEX |
Regex that mathes ANSI SGR sequences. |
Properties
protected array | $styles | Styles. | |
protected array | $userStyles | User styles. | |
protected array | $openTags | Open tags. |
Methods
Adds a user defined style.
Returns the tag name.
Returns TRUE if the tag is a closing tag and FALSE if not.
Returns ANSI SGR escape sequence for style reset.
Returns style codes associated with the tag name.
Returns ANSI SGR escape sequence for the chosen style(s).
Returns ANSI SGR escape sequence(s) for the chosen style(s) and adds the tag name to the array of open tags.
Returns ANSI SGR escape sequence for style reset and ANSI SGR escape sequence for parent style if the closed tag was nested.
Strips escape character from escaped tags.
Returns formatted string.
Returns a string where all formatting tags have been escaped.
Returns a string where all formatting tags have been stripped.
Returns a string where all SGR sequences have been stripped.
Details
at line 112
addStyle(string $name, array|string $style)
Adds a user defined style.
at line 123
protected string
getTagName(string $tag)
Returns the tag name.
at line 134
protected bool
isOpeningTag(string $tag)
Returns TRUE if the tag is a closing tag and FALSE if not.
at line 144
protected string
getSgrResetSequence()
Returns ANSI SGR escape sequence for style reset.
at line 155
protected array
getStyleCodes(string $tag)
Returns style codes associated with the tag name.
at line 182
protected string
getSgrStyleSequence(string $tag)
Returns ANSI SGR escape sequence for the chosen style(s).
at line 196
protected string
openStyle(string $tag)
Returns ANSI SGR escape sequence(s) for the chosen style(s) and adds the tag name to the array of open tags.
at line 210
protected string
closeStyle(string $tag)
Returns ANSI SGR escape sequence for style reset and ANSI SGR escape sequence for parent style if the closed tag was nested.
at line 246
protected string
removeTagEscapeCharacter(string $string)
Strips escape character from escaped tags.
at line 254
string
format(string $string)
Returns formatted string.
at line 300
string
escape(string $string)
Returns a string where all formatting tags have been escaped.
at line 308
string
stripTags(string $string)
Returns a string where all formatting tags have been stripped.
at line 319
string
stripSGR(string $string)
Returns a string where all SGR sequences have been stripped.