abstract class TemplateModifier

Constants

XMLNS_XSL

XSL namespace

Methods

static string
replaceTokens(string $template, string $regexp, callable $fn)

Replace parts of a template that match given regexp

static DOMNode
createReplacementNode(DOMDocument $dom, array $replacement)

Create a node that implements given replacement strategy

static void
replaceTokensInAttribute(DOMAttr $attribute, string $regexp, callable $fn)

Replace parts of an attribute that match given regexp

static void
replaceTokensInText(DOMText $node, string $regexp, callable $fn)

Replace parts of a text node that match given regexp

Details

at line 45
static string replaceTokens(string $template, string $regexp, callable $fn)

Replace parts of a template that match given regexp

Treats attribute values as plain text. Replacements within XPath expression is unsupported. The callback must return an array with two elements. The first must be either of 'expression', 'literal' or 'passthrough', and the second element depends on the first.

  • 'expression' indicates that the replacement must be treated as an XPath expression such as '@foo', which must be passed as the second element.

  • 'literal' indicates a literal (plain text) replacement, passed as its second element.

  • 'passthrough' indicates that the replacement should the tag's content. It works differently whether it is inside an attribute's value or a text node. Within an attribute's value, the replacement will be the text content of the tag. Within a text node, the replacement becomes an node. A second optional argument can be passed to be used as its @select node-set.

Parameters

string $template

Original template

string $regexp

Regexp for matching parts that need replacement

callable $fn

Callback used to get the replacement

Return Value

string

Processed template

at line 68
static protected DOMNode createReplacementNode(DOMDocument $dom, array $replacement)

Create a node that implements given replacement strategy

Parameters

DOMDocument $dom
array $replacement

Return Value

DOMNode

at line 99
static protected void replaceTokensInAttribute(DOMAttr $attribute, string $regexp, callable $fn)

Replace parts of an attribute that match given regexp

Parameters

DOMAttr $attribute Attribute
string $regexp

Regexp for matching parts that need replacement

callable $fn

Callback used to get the replacement

Return Value

void

at line 131
static protected void replaceTokensInText(DOMText $node, string $regexp, callable $fn)

Replace parts of a text node that match given regexp

Parameters

DOMText $node

Text node

string $regexp

Regexp for matching parts that need replacement

callable $fn

Callback used to get the replacement

Return Value

void