MediaWiki  master
TemplateParser Class Reference
Collaboration diagram for TemplateParser:

Public Member Functions

 __construct ($templateDir=null, $forceRecompile=false)
 
 enableRecursivePartials ($enable)
 Enable/disable the use of recursive partials. More...
 
 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

int $compileFlags = LightnCandy::FLAG_ERROR_EXCEPTION
 Compilation flags passed to LightnCandy. More...
 
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 25 of file TemplateParser.php.

Constructor & Destructor Documentation

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

Definition at line 52 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 185 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 163 of file TemplateParser.php.

References $code, and compile().

Referenced by getTemplate().

TemplateParser::enableRecursivePartials (   $enable)

Enable/disable the use of recursive partials.

Parameters
bool$enable

Definition at line 61 of file TemplateParser.php.

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 94 of file TemplateParser.php.

References $cache, $code, $compileFlags, $key, CACHE_ANYTHING, compileForEval(), 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 75 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 216 of file TemplateParser.php.

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

Member Data Documentation

int TemplateParser::$compileFlags = LightnCandy::FLAG_ERROR_EXCEPTION
protected

Compilation flags passed to LightnCandy.

Definition at line 46 of file TemplateParser.php.

Referenced by getTemplate().

bool TemplateParser::$forceRecompile = false
protected

Always compile template files.

Definition at line 39 of file TemplateParser.php.

Referenced by __construct().

callable [] TemplateParser::$renderers
protected

Array of cached rendering functions.

Definition at line 34 of file TemplateParser.php.

string TemplateParser::$templateDir
protected

The path to the Mustache templates.

Definition at line 29 of file TemplateParser.php.


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