class Document

Handles the generation and management of HTML document tags, such as meta tags, links, styles, scripts, manifest, robots, and sitemap.

Implements the singleton pattern.

Properties

string $title

Page title.

string $title_append

Text to append to the title.

string $canonical

Canonical URL of the page.

static Document|null $instance

Singleton instance of the class.

Methods

array
getLinks()

Returns all links added to the document.

static Document
get()

Returns the singleton instance of the Document class.

__construct()

Constructor. Sets the CSRFToken meta tag.

void
sitemap()

Generates and outputs the XML sitemap.

void
robots()

Generates and outputs the robots.txt file.

void
webmanifest()

Generates and outputs the web manifest file.

$this
setMetaTag(string $id, array $attributes)

Adds a meta tag to the document.

mixed
getMetaTags(string|null $tag = null)

Returns all meta tags, or a specific one if provided.

$this
appendLink(array $attributes, array $options = [])

Adds a link tag to the document.

$this
appendStyle(string $content, array $attributes = [], array $options = [])

Adds a CSS style to the document.

$this
appendScript(array $attributes, array $options = [])

Adds a JS script to the document.

$this
appendInlineScript(string $content, array $attributes = [], array $options = [])

Adds an inline JS script to the document.

string
renderMetaTags()

Returns rendered meta tags.

void
printMetaTags()

Prints rendered meta tags.

string
renderStyles()

Returns rendered links and styles.

void
printStyles()

Prints rendered links and styles.

string
renderScripts()

Returns rendered scripts (external and inline).

void
printScripts()

Prints rendered scripts.

void|null
printFaviconLinks()

Prints favicon links if available.

Details

Returns all links added to the document.

Return Value

array

at line 68
static Document get()

Returns the singleton instance of the Document class.

Return Value

Document

at line 78
__construct()

Constructor. Sets the CSRFToken meta tag.

at line 91
void sitemap()

Generates and outputs the XML sitemap.

Terminates script execution.

Return Value

void

at line 106
void robots()

Generates and outputs the robots.txt file.

Terminates script execution.

Return Value

void

at line 133
void webmanifest()

Generates and outputs the web manifest file.

Terminates script execution.

Return Value

void

at line 162
$this setMetaTag(string $id, array $attributes)

Adds a meta tag to the document.

Parameters

string $id

Meta tag identifier. Unique key for the meta tag.

array $attributes

Meta tag attributes. Associative array of meta tag attributes.

Return Value

$this

at line 176
mixed getMetaTags(string|null $tag = null)

Returns all meta tags, or a specific one if provided.

Parameters

string|null $tag

Meta tag identifier. If provided, returns the specific meta tag.

Return Value

mixed

Adds a link tag to the document.

Parameters

array $attributes

Associative array of link tag attributes.

array $options

Additional options for the link tag (e.g. id, preload).

Return Value

$this

at line 216
$this appendStyle(string $content, array $attributes = [], array $options = [])

Adds a CSS style to the document.

Parameters

string $content

CSS content to be added.

array $attributes

Associative array of style tag attributes.

array $options

Additional options for the style tag (e.g. id, group).

Return Value

$this

at line 236
$this appendScript(array $attributes, array $options = [])

Adds a JS script to the document.

Parameters

array $attributes

Associative array of script tag attributes.

array $options

Additional options for the script tag (e.g. id, preload).

Return Value

$this

at line 259
$this appendInlineScript(string $content, array $attributes = [], array $options = [])

Adds an inline JS script to the document.

Parameters

string $content

JavaScript code to be added inline.

array $attributes

Associative array of script tag attributes.

array $options

Additional options for the inline script (e.g. id, group).

Return Value

$this

at line 351
string renderMetaTags()

Returns rendered meta tags.

Return Value

string

at line 364
void printMetaTags()

Prints rendered meta tags.

Return Value

void

at line 373
string renderStyles()

Returns rendered links and styles.

Return Value

string

at line 394
void printStyles()

Prints rendered links and styles.

Return Value

void

at line 426
string renderScripts()

Returns rendered scripts (external and inline).

Return Value

string

at line 440
void printScripts()

Prints rendered scripts.

Return Value

void

Prints favicon links if available.

Return Value

void|null