MediaWiki  1.28.0
TemplateParser Class Reference
Collaboration diagram for TemplateParser:

Public Member Functions

 __construct ($templateDir=null, $forceRecompile=false)
 
 processTemplate ($templateName, $args, array $scopes=[])
 Returns HTML for a given template by calling the template function with the given args. More...
 

Protected Member Functions

 compile ($code)
 Compile the Mustache code into PHP code using LightnCandy. More...
 
 compileForEval ($fileContents, $filename)
 Wrapper for compile() function that verifies successful compilation and strips out the '<?php' part so that the code is ready for eval() More...
 
 getTemplate ($templateName)
 Returns a given template function if found, otherwise throws an exception. More...
 
 getTemplateFilename ($templateName)
 Constructs the location of the the source Mustache template. More...
 

Protected Attributes

bool $forceRecompile = false
 Always compile template files. More...
 
callable[] $renderers
 Array of cached rendering functions. More...
 
string $templateDir
 The path to the Mustache templates. More...
 

Detailed Description

Definition at line 23 of file TemplateParser.php.

Constructor & Destructor Documentation

TemplateParser::__construct (   $templateDir = null,
  $forceRecompile = false 
)
Parameters
string$templateDir
bool$forceRecompile

Definition at line 43 of file TemplateParser.php.

References $forceRecompile.

Member Function Documentation

TemplateParser::compile (   $code)
protected

Compile the Mustache code into PHP code using LightnCandy.

Parameters
string$codeMustache code
Returns
string PHP code (with '<?php')
Exceptions
RuntimeException

Definition at line 167 of file TemplateParser.php.

References $code.

Referenced by compileForEval().

TemplateParser::compileForEval (   $fileContents,
  $filename 
)
protected

Wrapper for compile() function that verifies successful compilation and strips out the '<?php' part so that the code is ready for eval()

Parameters
string$fileContentsMustache code
string$filenameName of the template
Returns
string PHP code (without '<?php')
Exceptions
RuntimeException

Definition at line 145 of file TemplateParser.php.

References $code, and compile().

Referenced by getTemplate().

TemplateParser::getTemplate (   $templateName)
protected

Returns a given template function if found, otherwise throws an exception.

Parameters
string$templateNameThe name of the template (without file suffix)
Returns
callable
Exceptions
RuntimeException

Definition at line 80 of file TemplateParser.php.

References $cache, $code, CACHE_ANYTHING, compileForEval(), ConfigFactory\getDefaultInstance(), ObjectCache\getLocalServerInstance(), and getTemplateFilename().

Referenced by processTemplate().

TemplateParser::getTemplateFilename (   $templateName)
protected

Constructs the location of the the source Mustache template.

Parameters
string$templateNameThe name of the template
Returns
string
Exceptions
UnexpectedValueExceptionIf $templateName attempts upwards directory traversal

Definition at line 54 of file TemplateParser.php.

Referenced by getTemplate().

TemplateParser::processTemplate (   $templateName,
  $args,
array  $scopes = [] 
)

Returns HTML for a given template by calling the template function with the given args.

echo $templateParser->processTemplate(
'ExampleTemplate',
[
'username' => $user->getName(),
'message' => 'Hello!'
]
);
Parameters
string$templateNameThe name of the template
mixed$args
array$scopes
Returns
string

Definition at line 200 of file TemplateParser.php.

References $args, $template, and getTemplate().

Member Data Documentation

bool TemplateParser::$forceRecompile = false
protected

Always compile template files.

Definition at line 37 of file TemplateParser.php.

Referenced by __construct().

callable [] TemplateParser::$renderers
protected

Array of cached rendering functions.

Definition at line 32 of file TemplateParser.php.

string TemplateParser::$templateDir
protected

The path to the Mustache templates.

Definition at line 27 of file TemplateParser.php.


The documentation for this class was generated from the following file: