class vB_TemplateParser

Extendable class to parse templates to be evaled. Supports proprietary tags through a modular class system. Uses DOM-parsing.

Properties

$text
$outputVar
$dom_doc

Methods

__construct(string $text)

Constructor.

static boolean
validPHPVariable(string $name)

Validate the name of a variable to ensure its valid PHP

boolean
validate(array $errors)

Validate the text for invalid tag nesting and usage (eg, an elseif after an else).

validate_curly($node, $errors)

No description

string
compile()

Compile the template into a directly eval()'able format.

string
_parse_nodes(array $nodes)

Parse an array of nodes. Append the output to a variable in order of occurrance.

string
_default_node_handler(object $node)

Default way to handle a node. If it's text, use that class. If it's a tag, look for a specific tag handler and use it if possible; if not, ignore it and parse the children.

string
_escape_string(string $string)

Default way to escape a string. Suitable for evaling.

array
fetch_dom_compatible()

Fetch the DOM-compatible version of the tokenized version of this template.

Details

at line 906
__construct(string $text)

Constructor.

Parameters

string $text Text to parse

at line 927
static boolean validPHPVariable(string $name)

Validate the name of a variable to ensure its valid PHP

Parameters

string $name Name of the variable

Return Value

boolean True if valid, else false

at line 943
boolean validate(array $errors)

Validate the text for invalid tag nesting and usage (eg, an elseif after an else).

Parameters

array $errors An array of errors. An extra return value!

Return Value

boolean True on success, false on failure

at line 1056
protected validate_curly($node, $errors)

Parameters

$node
$errors

at line 1095
string compile()

Compile the template into a directly eval()'able format.

Return Value

string Evalable version of the template

at line 1123
string _parse_nodes(array $nodes)

Parse an array of nodes. Append the output to a variable in order of occurrance.

Parameters

array $nodes An array of DOMNodes

Return Value

string Outputtable string

at line 1158
string _default_node_handler(object $node)

Default way to handle a node. If it's text, use that class. If it's a tag, look for a specific tag handler and use it if possible; if not, ignore it and parse the children.

Parameters

object $node DOMNode object

Return Value

string Outputtable string

at line 1203
string _escape_string(string $string)

Default way to escape a string. Suitable for evaling.

Parameters

string $string String to escape

Return Value

string Escaped string

at line 1215
array fetch_dom_compatible()

Fetch the DOM-compatible version of the tokenized version of this template.

Note that the tokens must be well-formed (proper nesting, all closed). Make sure it passes validate() first!

Return Value

array Array of nodes in a DOM-compatible format