class Document

Document class, provides an easy interface to parse and display a document

Properties

string $title Document title
string $description Document description
Document full URL
string $base Document base URL
string $language Contains the document language setting
string $direction Contains the document direction setting
string $_generator Document generator
string|Date $_mdate Document modified date
string $_tab Tab string
string $_lineEnd Contains the line end string
string $_charset Contains the character encoding string
string $_mime Document mime type
string $_namespace Document namespace
string $_profile Document profile
array $_scripts Array of linked scripts
array $_script Array of scripts placed in the header
array $_styleSheets Array of linked style sheets
array $_style Array of included style declarations
array $_metaTags Array of meta tags
object $_engine The rendering engine
string $_type The document type
static mixed $_buffer Array of buffered output

Methods

__construct( array $options = array())

Class constructor.

static  object
getInstance( string $type = 'html', array $attributes = array())

Returns the global Document object, only creating it if it doesn't already exist.

setType( string $type)

Set the document type

string
getType()

Returns the document type

mixed
getBuffer()

Get the contents of the document buffer

setBuffer( string $content, array $options = array())

Set the contents of the document buffer

string
getMetaData( string $name, string $attribute = 'name')

Gets a meta tag.

setMetaData( string $name, mixed $content, string $attribute = 'name')

Sets or alters a meta tag.

addScript( string $url, array $options = array(), array $attribs = array())

Adds a linked script to the page

addScriptVersion( string $url, array $options = array(), array $attribs = array())

Adds a linked script to the page with a version to allow to flush it. Ex: myscript.js?54771616b5bceae9df03c6173babf11d If not specified Joomla! automatically handles versioning

addScriptDeclaration( string $content, string $type = 'text/javascript')

Adds a script to the page

addScriptOptions( string $key, mixed $options, bool $merge = true)

Add option for script

array
getScriptOptions( string $key = null)

Get script(s) options

addStyleSheet( string $url, array $options = array(), array $attribs = array())

Adds a linked stylesheet to the page

addStyleSheetVersion( string $url, array $options = array(), array $attribs = array())

Adds a linked stylesheet version to the page. Ex: template.css?54771616b5bceae9df03c6173babf11d If not specified Joomla! automatically handles versioning

addStyleDeclaration( string $content, string $type = 'text/css')

Adds a stylesheet declaration to the page

setCharset( string $type = 'utf-8')

Sets the document charset

string
getCharset()

Returns the document charset encoding.

setLanguage( string $lang = 'en-gb')

Sets the global document language declaration. Default is English (en-gb).

string
getLanguage()

Returns the document language.

setDirection( string $dir = 'ltr')

Sets the global document direction declaration. Default is left-to-right (ltr).

string
getDirection()

Returns the document direction declaration.

setTitle( string $title)

Sets the title of the document

string
getTitle()

Return the title of the document.

setMediaVersion( string $mediaVersion)

Set the assets version

string
getMediaVersion()

Return the media version

setBase( string $base)

Sets the base URI of the document

string
getBase()

Return the base URI of the document.

setDescription( string $description)

Sets the description of the document

string
getDescription()

Return the description of the document.

setLink( string $url)

Sets the document link

string
getLink()

Returns the document base url

setGenerator( string $generator)

Sets the document generator

string
getGenerator()

Returns the document generator

setModifiedDate( string|Date $date)

Sets the document modified date

string|Date
getModifiedDate()

Returns the document modified date

setMimeEncoding( string $type = 'text/html', boolean $sync = true)

Sets the document MIME encoding that is sent to the browser.

string
getMimeEncoding()

Return the document MIME encoding that is sent to the browser.

setLineEnd( string $style)

Sets the line end style to Windows, Mac, Unix or a custom string.

string
_getLineEnd()

Returns the lineEnd

setTab( string $string)

Sets the string used to indent HTML

string
_getTab()

Returns a string containing the unit for indenting HTML

loadRenderer( string $type)

Load a renderer

parse( array $params = array())

Parses the document and prepares the buffers

void
render( boolean $cache = false, array $params = array())

Outputs the document

Details

__construct( array $options = array())

Class constructor.

Parameters

array $options Associative array of options

static object getInstance( string $type = 'html', array $attributes = array())

Returns the global Document object, only creating it if it doesn't already exist.

Parameters

string $type The document type to instantiate
array $attributes Array of attributes

Return Value

object The document object.

Document setType( string $type)

Set the document type

Parameters

string $type Type document is to set to

Return Value

Document instance of $this to allow chaining

string getType()

Returns the document type

Return Value

string

mixed getBuffer()

Get the contents of the document buffer

Return Value

mixed

Document setBuffer( string $content, array $options = array())

Set the contents of the document buffer

Parameters

string $content The content to be set in the buffer.
array $options Array of optional elements.

Return Value

Document instance of $this to allow chaining

string getMetaData( string $name, string $attribute = 'name')

Gets a meta tag.

Parameters

string $name Name of the meta HTML tag
string $attribute Attribute to use in the meta HTML tag

Return Value

string

Document setMetaData( string $name, mixed $content, string $attribute = 'name')

Sets or alters a meta tag.

Parameters

string $name Name of the meta HTML tag
mixed $content Value of the meta HTML tag as array or string
string $attribute Attribute to use in the meta HTML tag

Return Value

Document instance of $this to allow chaining

Document addScript( string $url, array $options = array(), array $attribs = array())

Adds a linked script to the page

Parameters

string $url URL to the linked script.
array $options Array of options. Example: array('version' => 'auto', 'conditional' => 'lt IE 9')
array $attribs Array of attributes. Example: array('id' => 'scriptid', 'async' => 'async', 'data-test' => 1)

Return Value

Document instance of $this to allow chaining

Document addScriptVersion( string $url, array $options = array(), array $attribs = array())

Adds a linked script to the page with a version to allow to flush it. Ex: myscript.js?54771616b5bceae9df03c6173babf11d If not specified Joomla! automatically handles versioning

Parameters

string $url URL to the linked script.
array $options Array of options. Example: array('version' => 'auto', 'conditional' => 'lt IE 9')
array $attribs Array of attributes. Example: array('id' => 'scriptid', 'async' => 'async', 'data-test' => 1)

Return Value

Document instance of $this to allow chaining

Document addScriptDeclaration( string $content, string $type = 'text/javascript')

Adds a script to the page

Parameters

string $content Script
string $type Scripting mime (defaults to 'text/javascript')

Return Value

Document instance of $this to allow chaining

Document addScriptOptions( string $key, mixed $options, bool $merge = true)

Add option for script

Parameters

string $key Name in Storage
mixed $options Scrip options as array or string
bool $merge Whether merge with existing (true) or replace (false)

Return Value

Document instance of $this to allow chaining

array getScriptOptions( string $key = null)

Get script(s) options

Parameters

string $key Name in Storage

Return Value

array Options for given $key, or all script options

Document addStyleSheet( string $url, array $options = array(), array $attribs = array())

Adds a linked stylesheet to the page

Parameters

string $url URL to the linked style sheet
array $options Array of options. Example: array('version' => 'auto', 'conditional' => 'lt IE 9')
array $attribs Array of attributes. Example: array('id' => 'stylesheet', 'data-test' => 1)

Return Value

Document instance of $this to allow chaining

Document addStyleSheetVersion( string $url, array $options = array(), array $attribs = array())

Adds a linked stylesheet version to the page. Ex: template.css?54771616b5bceae9df03c6173babf11d If not specified Joomla! automatically handles versioning

Parameters

string $url URL to the linked style sheet
array $options Array of options. Example: array('version' => 'auto', 'conditional' => 'lt IE 9')
array $attribs Array of attributes. Example: array('id' => 'stylesheet', 'data-test' => 1)

Return Value

Document instance of $this to allow chaining

Document addStyleDeclaration( string $content, string $type = 'text/css')

Adds a stylesheet declaration to the page

Parameters

string $content Style declarations
string $type Type of stylesheet (defaults to 'text/css')

Return Value

Document instance of $this to allow chaining

Document setCharset( string $type = 'utf-8')

Sets the document charset

Parameters

string $type Charset encoding string

Return Value

Document instance of $this to allow chaining

string getCharset()

Returns the document charset encoding.

Return Value

string

Document setLanguage( string $lang = 'en-gb')

Sets the global document language declaration. Default is English (en-gb).

Parameters

string $lang The language to be set

Return Value

Document instance of $this to allow chaining

string getLanguage()

Returns the document language.

Return Value

string

Document setDirection( string $dir = 'ltr')

Sets the global document direction declaration. Default is left-to-right (ltr).

Parameters

string $dir The language direction to be set

Return Value

Document instance of $this to allow chaining

string getDirection()

Returns the document direction declaration.

Return Value

string

Document setTitle( string $title)

Sets the title of the document

Parameters

string $title The title to be set

Return Value

Document instance of $this to allow chaining

string getTitle()

Return the title of the document.

Return Value

string

Document setMediaVersion( string $mediaVersion)

Set the assets version

Parameters

string $mediaVersion Media version to use

Return Value

Document instance of $this to allow chaining

string getMediaVersion()

Return the media version

Return Value

string

Document setBase( string $base)

Sets the base URI of the document

Parameters

string $base The base URI to be set

Return Value

Document instance of $this to allow chaining

string getBase()

Return the base URI of the document.

Return Value

string

Document setDescription( string $description)

Sets the description of the document

Parameters

string $description The description to set

Return Value

Document instance of $this to allow chaining

string getDescription()

Return the description of the document.

Return Value

string

Sets the document link

Parameters

string $url A url

Return Value

Document instance of $this to allow chaining

Returns the document base url

Return Value

string

Document setGenerator( string $generator)

Sets the document generator

Parameters

string $generator The generator to be set

Return Value

Document instance of $this to allow chaining

string getGenerator()

Returns the document generator

Return Value

string

Document setModifiedDate( string|Date $date)

Sets the document modified date

Parameters

string|Date $date The date to be set

Return Value

Document instance of $this to allow chaining

Exceptions

InvalidArgumentException

string|Date getModifiedDate()

Returns the document modified date

Return Value

string|Date

Document setMimeEncoding( string $type = 'text/html', boolean $sync = true)

Sets the document MIME encoding that is sent to the browser.

This usually will be text/html because most browsers cannot yet accept the proper mime settings for XHTML: application/xhtml+xml and to a lesser extent application/xml and text/xml. See the W3C note ({@link http://www.w3.org/TR/xhtml-media-types/ http://www.w3.org/TR/xhtml-media-types/}) for more details.

Parameters

string $type The document type to be sent
boolean $sync Should the type be synced with HTML?

Return Value

Document instance of $this to allow chaining

string getMimeEncoding()

Return the document MIME encoding that is sent to the browser.

Return Value

string

Document setLineEnd( string $style)

Sets the line end style to Windows, Mac, Unix or a custom string.

Parameters

string $style "win", "mac", "unix" or custom string.

Return Value

Document instance of $this to allow chaining

string _getLineEnd()

Returns the lineEnd

Return Value

string

Document setTab( string $string)

Sets the string used to indent HTML

Parameters

string $string String used to indent ("\11", "\t", ' ', etc.).

Return Value

Document instance of $this to allow chaining

string _getTab()

Returns a string containing the unit for indenting HTML

Return Value

string

DocumentRenderer loadRenderer( string $type)

Load a renderer

Parameters

string $type The renderer type

Return Value

DocumentRenderer

Exceptions

RuntimeException

Document parse( array $params = array())

Parses the document and prepares the buffers

Parameters

array $params The array of parameters

Return Value

Document instance of $this to allow chaining

void render( boolean $cache = false, array $params = array())

Outputs the document

Parameters

boolean $cache If true, cache the output
array $params Associative array of attributes

Return Value

void The rendered data