Moodle PHP Documentation 4.2
Moodle 4.2.8 (Build: 20240610) (2d41ac46f45)
|
Public Member Functions | |
__construct (array $options=array()) | |
Mustache class constructor. | |
addHelper ($name, $helper) | |
Add a new Mustache helper. | |
getCache () | |
Get the current Mustache Cache instance. | |
getCharset () | |
Get the current Mustache character set. | |
getCompiler () | |
Get the current Mustache Compiler instance. | |
getEntityFlags () | |
Get the current Mustache entitity type to escape. | |
getEscape () | |
Get the current Mustache escape callback. | |
getHelper ($name) | |
Get a Mustache helper by name. | |
getHelpers () | |
Get the current set of Mustache helpers. | |
getLoader () | |
Get the current Mustache template Loader instance. | |
getLogger () | |
Get the current Mustache Logger instance. | |
getParser () | |
Get the current Mustache Parser instance. | |
getPartialsLoader () | |
Get the current Mustache partials Loader instance. | |
getPragmas () | |
Get the current globally enabled pragmas. | |
getTemplateClassName ($source) | |
Helper method to generate a Mustache template class. | |
getTokenizer () | |
Get the current Mustache Tokenizer instance. | |
hasHelper ($name) | |
Check whether this Mustache instance has a helper. | |
loadLambda ($source, $delims=null) | |
Load a Mustache lambda Template by source. | |
loadPartial ($name) | |
Load a Mustache partial Template by name. | |
loadTemplate ($name) | |
Load a Mustache Template by name. | |
removeHelper ($name) | |
Remove a helper by name. | |
render ($template, $context=array()) | |
Shortcut 'render' invocation. | |
setCache (Mustache_Cache $cache) | |
Set the Mustache Cache instance. | |
setCompiler (Mustache_Compiler $compiler) | |
Set the Mustache Compiler instance. | |
setHelpers ($helpers) | |
Set an array of Mustache helpers. | |
setLoader (Mustache_Loader $loader) | |
Set the Mustache template Loader instance. | |
setLogger ($logger=null) | |
Set the Mustache Logger instance. | |
setParser (Mustache_Parser $parser) | |
Set the Mustache Parser instance. | |
setPartials (array $partials=array()) | |
Set partials for the current partials Loader instance. | |
setPartialsLoader (Mustache_Loader $partialsLoader) | |
Set the Mustache partials Loader instance. | |
setTokenizer (Mustache_Tokenizer $tokenizer) | |
Set the Mustache Tokenizer instance. | |
Public Attributes | |
const | PRAGMA_ANCHORED_DOT = 'ANCHORED-DOT' |
const | PRAGMA_BLOCKS = 'BLOCKS' |
const | PRAGMA_FILTERS = 'FILTERS' |
const | SPEC_VERSION = '1.2.2' |
const | VERSION = '2.14.2' |
Protected Member Functions | |
getLambdaCache () | |
Get the current Lambda Cache instance. | |
Mustache_Engine::__construct | ( | array | $options = array() | ) |
Mustache class constructor.
Passing an $options array allows overriding certain Mustache options during instantiation:
$options = array( // The class prefix for compiled templates. Defaults to '__Mustache_'. 'template_class_prefix' => '__MyTemplates_', // A Mustache cache instance or a cache directory string for compiled templates. // Mustache will not cache templates unless this is set. 'cache' => dirname(__FILE__).'/tmp/cache/mustache', // Override default permissions for cache files. Defaults to using the system-defined umask. It is // *strongly* recommended that you configure your umask properly rather than overriding permissions here. 'cache_file_mode' => 0666, // Optionally, enable caching for lambda section templates. This is generally not recommended, as lambda // sections are often too dynamic to benefit from caching. 'cache_lambda_templates' => true, // Customize the tag delimiters used by this engine instance. Note that overriding here changes the // delimiters used to parse all templates and partials loaded by this instance. To override just for a // single template, use an inline "change delimiters" tag at the start of the template file: // // {{=<% %>=}} // 'delimiters' => '<% %>', // A Mustache template loader instance. Uses a StringLoader if not specified. 'loader' => new Mustache_Loader_FilesystemLoader(dirname(__FILE__).'/views'), // A Mustache loader instance for partials. 'partials_loader' => new Mustache_Loader_FilesystemLoader(dirname(__FILE__).'/views/partials'), // An array of Mustache partials. Useful for quick-and-dirty string template loading, but not as // efficient or lazy as a Filesystem (or database) loader. 'partials' => array('foo' => file_get_contents(dirname(__FILE__).'/views/partials/foo.mustache')), // An array of 'helpers'. Helpers can be global variables or objects, closures (e.g. for higher order // sections), or any other valid Mustache context value. They will be prepended to the context stack, // so they will be available in any template loaded by this Mustache instance. 'helpers' => array('i18n' => function ($text) { // do something translatey here... }), // An 'escape' callback, responsible for escaping double-mustache variables. 'escape' => function ($value) { return htmlspecialchars($buffer, ENT_COMPAT, 'UTF-8'); }, // Type argument for `htmlspecialchars`. Defaults to ENT_COMPAT. You may prefer ENT_QUOTES. 'entity_flags' => ENT_QUOTES, // Character set for `htmlspecialchars`. Defaults to 'UTF-8'. Use 'UTF-8'. 'charset' => 'ISO-8859-1', // A Mustache Logger instance. No logging will occur unless this is set. Using a PSR-3 compatible // logging library -- such as Monolog -- is highly recommended. A simple stream logger implementation is // available as well: 'logger' => new Mustache_Logger_StreamLogger('php://stderr'), // Only treat Closure instances and invokable classes as callable. If true, values like // `array('ClassName', 'methodName')` and `array($classInstance, 'methodName')`, which are traditionally // "callable" in PHP, are not called to resolve variables for interpolation or section contexts. This // helps protect against arbitrary code execution when user input is passed directly into the template. // This currently defaults to false, but will default to true in v3.0. 'strict_callables' => true, // Do not render the output of lambdas. Use this to prevent repeated rendering if the lambda already // takes care of rendering its content. This helps protect against mustache code injection when user // input is passed directly into the template. Defaults to false. 'disable_lambda_rendering' => true, // Enable pragmas across all templates, regardless of the presence of pragma tags in the individual // templates. 'pragmas' => [Mustache_Engine::PRAGMA_FILTERS], );
Mustache_Exception_InvalidArgumentException | If escape option is not callable |
array | $options | (default: array()) |
Reimplemented in core\output\mustache_engine.
Mustache_Engine::addHelper | ( | $name, | |
$helper ) |
Mustache_Engine::getCache | ( | ) |
Get the current Mustache Cache instance.
If no Cache instance has been explicitly specified, this method will instantiate and return a new one.
Mustache_Cache |
Mustache_Engine::getCharset | ( | ) |
Get the current Mustache character set.
string |
Mustache_Engine::getCompiler | ( | ) |
Get the current Mustache Compiler instance.
If no Compiler instance has been explicitly specified, this method will instantiate and return a new one.
Mustache_Compiler |
Mustache_Engine::getEntityFlags | ( | ) |
Get the current Mustache entitity type to escape.
int |
Mustache_Engine::getEscape | ( | ) |
Get the current Mustache escape callback.
callable|null |
Mustache_Engine::getHelper | ( | $name | ) |
Get a Mustache helper by name.
string | $name |
mixed | Helper |
Mustache_Engine::getHelpers | ( | ) |
Get the current set of Mustache helpers.
Mustache_HelperCollection |
Reimplemented in core\output\mustache_engine.
|
protected |
Get the current Lambda Cache instance.
If 'cache_lambda_templates' is enabled, this is the default cache instance. Otherwise, it is a NoopCache.
Mustache_Cache |
Mustache_Engine::getLoader | ( | ) |
Get the current Mustache template Loader instance.
If no Loader instance has been explicitly specified, this method will instantiate and return a StringLoader instance.
Mustache_Loader |
Mustache_Engine::getLogger | ( | ) |
Get the current Mustache Logger instance.
Mustache_Logger|Psr\Log\LoggerInterface |
Mustache_Engine::getParser | ( | ) |
Get the current Mustache Parser instance.
If no Parser instance has been explicitly specified, this method will instantiate and return a new one.
Mustache_Parser |
Mustache_Engine::getPartialsLoader | ( | ) |
Get the current Mustache partials Loader instance.
If no Loader instance has been explicitly specified, this method will instantiate and return an ArrayLoader instance.
Mustache_Loader |
Mustache_Engine::getPragmas | ( | ) |
Get the current globally enabled pragmas.
array |
Mustache_Engine::getTemplateClassName | ( | $source | ) |
Helper method to generate a Mustache template class.
This method must be updated any time options are added which make it so the same template could be parsed and compiled multiple different ways.
string | Mustache_Source | $source |
string | Mustache Template class name |
Mustache_Engine::getTokenizer | ( | ) |
Get the current Mustache Tokenizer instance.
If no Tokenizer instance has been explicitly specified, this method will instantiate and return a new one.
Mustache_Tokenizer |
Mustache_Engine::hasHelper | ( | $name | ) |
Check whether this Mustache instance has a helper.
string | $name |
bool | True if the helper is present |
Mustache_Engine::loadLambda | ( | $source, | |
$delims = null ) |
Load a Mustache lambda Template by source.
This is a helper method used by Template instances to generate subtemplates for Lambda sections. You can most likely ignore it completely.
string | $source | |
string | $delims | (default: null) |
Mustache_Template |
Mustache_Engine::loadPartial | ( | $name | ) |
Load a Mustache partial Template by name.
This is a helper method used internally by Template instances for loading partial templates. You can most likely ignore it completely.
string | $name |
Mustache_Template |
Mustache_Engine::loadTemplate | ( | $name | ) |
Mustache_Engine::removeHelper | ( | $name | ) |
Mustache_Engine::render | ( | $template, | |
$context = array() ) |
Shortcut 'render' invocation.
Equivalent to calling $mustache->loadTemplate($template)->render($context);
string | $template | |
mixed | $context | (default: array()) |
string | Rendered template |
Mustache_Engine::setCache | ( | Mustache_Cache | $cache | ) |
Set the Mustache Cache instance.
Mustache_Cache | $cache |
Mustache_Engine::setCompiler | ( | Mustache_Compiler | $compiler | ) |
Set the Mustache Compiler instance.
Mustache_Compiler | $compiler |
Mustache_Engine::setHelpers | ( | $helpers | ) |
Set an array of Mustache helpers.
An array of 'helpers'. Helpers can be global variables or objects, closures (e.g. for higher order sections), or any other valid Mustache context value. They will be prepended to the context stack, so they will be available in any template loaded by this Mustache instance.
Mustache_Exception_InvalidArgumentException | if $helpers is not an array or Traversable |
array | Traversable | $helpers |
Mustache_Engine::setLoader | ( | Mustache_Loader | $loader | ) |
Set the Mustache template Loader instance.
Mustache_Loader | $loader |
Mustache_Engine::setLogger | ( | $logger = null | ) |
Set the Mustache Logger instance.
Mustache_Exception_InvalidArgumentException | If logger is not an instance of Mustache_Logger or Psr\Log\LoggerInterface |
Mustache_Logger | Psr\Log\LoggerInterface | $logger |
Mustache_Engine::setParser | ( | Mustache_Parser | $parser | ) |
Set the Mustache Parser instance.
Mustache_Parser | $parser |
Mustache_Engine::setPartials | ( | array | $partials = array() | ) |
Set partials for the current partials Loader instance.
Mustache_Exception_RuntimeException | If the current Loader instance is immutable |
array | $partials | (default: array()) |
Mustache_Engine::setPartialsLoader | ( | Mustache_Loader | $partialsLoader | ) |
Set the Mustache partials Loader instance.
Mustache_Loader | $partialsLoader |
Mustache_Engine::setTokenizer | ( | Mustache_Tokenizer | $tokenizer | ) |
Set the Mustache Tokenizer instance.
Mustache_Tokenizer | $tokenizer |