class Formatter
Properties
Methods
`$config` is optional because extensions subclass this and call `parent::__construct()` with the two arguments that existed before it was added. When it is absent the forum's address is resolved from the container instead, so those subclasses keep working untouched.
No description
Build and cache the formatter now, rather than leaving it to the first post that needs rendering.
Let the link template carry attributes decided when a post is rendered.
Show a link to a discussion as the discussion it points at.
Decide how each link in a post should be treated, based on where it goes.
Pick out the discussion a URL points at, if it points at one.
Converts a plain text string (with or without Markdown) to it's HTML equivalent.
Details
at
line 52
__construct( Repository $cache, string $cacheDir, Config|null $config = null)
`$config` is optional because extensions subclass this and call `parent::__construct()` with the two arguments that existed before it was added. When it is absent the forum's address is resolved from the container instead, so those subclasses keep working untouched.
at
line 62
void
addConfigurationCallback(callable $callback)
at
line 70
void
addParsingCallback(callable $callback)
at
line 78
void
addUnparsingCallback(callable $callback)
at
line 86
void
addRenderingCallback(callable $callback)
at
line 109
string
render(string $xml, mixed $context = null, ServerRequestInterface|null $request = null)
at
line 122
string|null
unparse(string|null $xml, mixed $context = null)
at
line 138
void
flush()
Flush the cache so that the formatter components are regenerated.
at
line 153
void
warm()
Build and cache the formatter now, rather than leaving it to the first post that needs rendering.
Compiling the renderer can be expensive on a forum with many extensions, and it happens lazily inside whichever request first renders a post after the cache was cleared. On a tight web memory limit that request can hit a fatal and fail silently. Warming here — from `cache:clear`, where the limit is usually higher — keeps that cost out of the render path.
at
line 160
protected Configurator
getConfigurator()
at
line 198
protected void
configureExternalLinks( Configurator $configurator)
Let the link template carry attributes decided when a post is rendered.
Whether a link points back at this forum is not known when the post is written — the forum may since have moved — so `rel`, `target` and `class` are worked out at render time and copied through here. A theme that replaces this template needs to copy them too, or links lose the treatment.
at
line 228
protected void
configureDiscussionLinks( Configurator $configurator)
Show a link to a discussion as the discussion it points at.
A pasted address says nothing useful in the middle of a sentence, so where the writer pasted one bare — leaving the address as the link's own text — it is shown as `#123` instead, with the post number alongside it when the link points at a particular reply. When the writer chose their own words for the link, those words are what appears; the label replaces an address, never a sentence.
at
line 255
protected string
getDiscussionLinkTemplate()
The markup for a discussion link that is showing its label.
at
line 281
protected mixed
getComponent(string $name)
Get a TextFormatter component ("renderer" or "parser" or "js").
at
line 290
protected Parser
getParser(mixed $context = null)
at
line 299
protected Renderer
getRenderer()
at
line 313
string
getJs()
Get the formatter JavaScript.
at
line 324
protected string
configureDefaultsOnLinks(string $xml)
Decide how each link in a post should be treated, based on where it goes.
Only fills in what has not already been set, so an extension rendering callback — which runs before this — keeps the last word on any link.
at
line 370
protected array|null
parseDiscussionUrl(string $url)
Pick out the discussion a URL points at, if it points at one.
Matches the shape the discussion route declares: an id, optionally followed by a slug that carries no meaning here, and optionally a post number after it.
at
line 406
protected string|null
getFaviconUrl()
The forum's favicon, if one has been uploaded.
Looked up once per request for the same reason as the forum's address: this is consulted for every discussion link on the page.
at
line 436
protected array
getForumOrigin()
The forum's host and base path.
`Config::url()` builds a fresh Uri on every call, and this is consulted once per link in every post on the page, so the answer is kept rather than rebuilt. It cannot change within a request.
at
line 460
protected bool
isInternalUrl(string $url)
Does this URL point back at the forum itself?
Host and path both have to match: a forum installed at example.com/forum does not own example.com/shop. The scheme is ignored, since a forum reachable over both http and https is still one forum, and a link is not a different destination for having been copied before the certificate was installed.
at
line 505
string
convert(string|null $content)
Converts a plain text string (with or without Markdown) to it's HTML equivalent.