FormattedText
in package
implements
JsonSerializable
Formatted text with styling support.
Used for complex text content that requires inline styling, additions, or specific formatting.
Tags
Table of Contents
Interfaces
- JsonSerializable
Constants
- FORMAT_HTML = 'html'
- Valid format types.
- FORMAT_MARKDOWN = 'markdown'
- FORMAT_NONE = 'none'
Properties
- $additions : array<int, AdditionInterface>|null
- Additions (links, etc.).
- $format : string|null
- The text format.
- $inlineTextStyles : array<int, array<string, mixed>>|null
- Inline text styles.
- $text : string
- $textStyle : string|null
- The text style reference.
Methods
- __construct() : mixed
- Create a new FormattedText.
- addAddition() : $this
- Add an addition.
- addInlineTextStyle() : $this
- Add an inline text style.
- html() : self
- Create formatted text from HTML.
- jsonSerialize() : array<string, mixed>
- {@inheritdoc}
- markdown() : self
- Create formatted text from Markdown.
- plain() : self
- Create formatted text from plain text.
- setAdditions() : $this
- Set additions.
- setFormat() : $this
- Set the text format.
- setInlineTextStyles() : $this
- Set inline text styles.
- setTextStyle() : $this
- Set the text style reference.
Constants
FORMAT_HTML
Valid format types.
public
mixed
FORMAT_HTML
= 'html'
FORMAT_MARKDOWN
public
mixed
FORMAT_MARKDOWN
= 'markdown'
FORMAT_NONE
public
mixed
FORMAT_NONE
= 'none'
Properties
$additions
Additions (links, etc.).
private
array<int, AdditionInterface>|null
$additions
= null
$format
The text format.
private
string|null
$format
= null
$inlineTextStyles
Inline text styles.
private
array<int, array<string, mixed>>|null
$inlineTextStyles
= null
$text read-only
private
string
$text
$textStyle
The text style reference.
private
string|null
$textStyle
= null
Methods
__construct()
Create a new FormattedText.
public
__construct(string $text) : mixed
Parameters
- $text : string
-
The text content.
addAddition()
Add an addition.
public
addAddition(AdditionInterface $addition) : $this
Parameters
- $addition : AdditionInterface
-
The addition.
Return values
$thisaddInlineTextStyle()
Add an inline text style.
public
addInlineTextStyle(int $rangeStart, int $rangeLength, string|array<string, mixed> $textStyle) : $this
Parameters
- $rangeStart : int
-
The starting position.
- $rangeLength : int
-
The length.
- $textStyle : string|array<string, mixed>
-
The text style name or inline definition.
Return values
$thishtml()
Create formatted text from HTML.
public
static html(string $html) : self
Parameters
- $html : string
-
The HTML content.
Return values
self —A new instance.
jsonSerialize()
{@inheritdoc}
public
jsonSerialize() : array<string, mixed>
Return values
array<string, mixed>markdown()
Create formatted text from Markdown.
public
static markdown(string $markdown) : self
Parameters
- $markdown : string
-
The Markdown content.
Return values
self —A new instance.
plain()
Create formatted text from plain text.
public
static plain(string $text) : self
Parameters
- $text : string
-
The text content.
Return values
self —A new instance.
setAdditions()
Set additions.
public
setAdditions(array<int, AdditionInterface> $additions) : $this
Parameters
- $additions : array<int, AdditionInterface>
-
The additions.
Return values
$thissetFormat()
Set the text format.
public
setFormat(string $format) : $this
Parameters
- $format : string
-
One of 'html', 'markdown', 'none'.
Return values
$thissetInlineTextStyles()
Set inline text styles.
public
setInlineTextStyles(array<int, array<string, mixed>> $styles) : $this
Parameters
- $styles : array<int, array<string, mixed>>
-
The inline styles.
Return values
$thissetTextStyle()
Set the text style reference.
public
setTextStyle(string $textStyle) : $this
Parameters
- $textStyle : string
-
The text style name.