Search moodle.org's
Developer Documentation

See Release Notes
Long Term Support Release

  • Bug fixes for general core bugs in 4.1.x will end 13 November 2023 (12 months).
  • Bug fixes for security issues in 4.1.x will end 10 November 2025 (36 months).
  • PHP version: minimum PHP 7.4.0 Note: minimum PHP version has increased since Moodle 4.0. PHP 8.0.x is supported too.

Differences Between: [Versions 310 and 401]

(no description)

File Size: 716 lines (24 kb)
Included or required:0 times
Referenced: 0 times
Includes or requires: 0 files

Defines 1 class

Mustache_Compiler:: (24 methods):
  compile()
  setPragmas()
  walk()
  renderInternal()
  renderInternal()
  writeCode()
  blockVar()
  blockArg()
  block()
  section()
  getSection()
  section()
  invertedSection()
  partial()
  parent()
  onlyBlockArgs()
  variable()
  getFilters()
  text()
  prepare()
  getEscape()
  getFindMethod()
  getCallable()
  flushIndent()


Class: Mustache_Compiler  - X-Ref

Mustache Compiler class.

This class is responsible for turning a Mustache token parse tree into normal PHP source code.
compile($source, array $tree, $name, $customEscape = false, $charset = 'UTF-8', $strictCallables = false, $entityFlags = ENT_COMPAT, $disableLambdaRendering = false)   X-Ref
Compile a Mustache token parse tree into PHP source code.

param: string $source                 Mustache Template source code
param: array  $tree                   Parse tree of Mustache tokens
param: string $name                   Mustache Template class name
param: bool   $customEscape           (default: false)
param: string $charset                (default: 'UTF-8')
param: bool   $strictCallables        (default: false)
param: int    $entityFlags            (default: ENT_COMPAT)
param: bool   $disableLambdaRendering (default: false)
return: string Generated PHP source code

setPragmas(array $pragmas)   X-Ref
Enable pragmas across all templates, regardless of the presence of pragma
tags in the individual templates.

param: string[] $pragmas

walk(array $tree, $level = 0)   X-Ref
Helper function for walking the Mustache token parse tree.

param: array $tree  Parse tree of Mustache tokens
param: int   $level (default: 0)
return: string Generated PHP source code

renderInternal(Mustache_Context $context, $indent = \'\')   X-Ref
No description

renderInternal(Mustache_Context $context, $indent = \'\')   X-Ref
No description

writeCode($tree, $name)   X-Ref
Generate Mustache Template class PHP source.

param: array  $tree Parse tree of Mustache tokens
param: string $name Mustache Template class name
return: string Generated PHP source code

blockVar($nodes, $id, $start, $end, $otag, $ctag, $level)   X-Ref
Generate Mustache Template inheritance block variable PHP source.

param: array  $nodes Array of child tokens
param: string $id    Section name
param: int    $start Section start offset
param: int    $end   Section end offset
param: string $otag  Current Mustache opening tag
param: string $ctag  Current Mustache closing tag
param: int    $level
return: string Generated PHP source code

blockArg($nodes, $id, $start, $end, $otag, $ctag, $level)   X-Ref
Generate Mustache Template inheritance block argument PHP source.

param: array  $nodes Array of child tokens
param: string $id    Section name
param: int    $start Section start offset
param: int    $end   Section end offset
param: string $otag  Current Mustache opening tag
param: string $ctag  Current Mustache closing tag
param: int    $level
return: string Generated PHP source code

block({$indent = $buffer = \'\';%sreturn $buffer;}';/*** Generate Mustache Template inheritance block function PHP source.** @param array $nodes Array of child tokens** @return string key of new block function*/private function block($nodes)   X-Ref
No description

section({$buffer = \'\';if (%s)   X-Ref
No description

getSection($key, $callable, $source, $helper, $delims, $content)   X-Ref
Helper function to compile section with and without lambda rendering.

param: string $key
param: string $callable
param: string $source
param: string $helper
param: string $delims
param: string $content
return: string section code

section($nodes, $id, $filters, $start, $end, $otag, $ctag, $level)   X-Ref
Generate Mustache Template section PHP source.

param: array    $nodes   Array of child tokens
param: string   $id      Section name
param: string[] $filters Array of filters
param: int      $start   Section start offset
param: int      $end     Section end offset
param: string   $otag    Current Mustache opening tag
param: string   $ctag    Current Mustache closing tag
param: int      $level
return: string Generated section PHP source code

invertedSection($nodes, $id, $filters, $level)   X-Ref
Generate Mustache Template inverted section PHP source.

param: array    $nodes   Array of child tokens
param: string   $id      Section name
param: string[] $filters Array of filters
param: int      $level
return: string Generated inverted section PHP source code

partial($id, $indent, $level)   X-Ref
Generate Mustache Template partial call PHP source.

param: string $id     Partial name
param: string $indent Whitespace indent to apply to partial
param: int    $level
return: string Generated partial call PHP source code

parent($id, $indent, array $children, $level)   X-Ref
Generate Mustache Template inheritance parent call PHP source.

param: string $id       Parent tag name
param: string $indent   Whitespace indent to apply to parent
param: array  $children Child nodes
param: int    $level
return: string Generated PHP source code

onlyBlockArgs(array $node)   X-Ref
Helper method for filtering out non-block-arg tokens.

param: array $node
return: bool True if $node is a block arg token

variable($id, $filters, $escape, $level)   X-Ref
Generate Mustache Template variable interpolation PHP source.

param: string   $id      Variable name
param: string[] $filters Array of filters
param: bool     $escape  Escape the variable value for output?
param: int      $level
return: string Generated variable interpolation PHP source

getFilters(array $filters, $level)   X-Ref
Generate Mustache Template variable filtering PHP source.

param: string[] $filters Array of filters
param: int      $level
return: string Generated filter PHP source

text($text, $level)   X-Ref
Generate Mustache Template output Buffer call PHP source.

param: string $text
param: int    $level
return: string Generated output Buffer call PHP source

prepare($text, $bonus = 0, $prependNewline = true, $appendNewline = false)   X-Ref
Prepare PHP source code snippet for output.

param: string $text
param: int    $bonus          Additional indent level (default: 0)
param: bool   $prependNewline Prepend a newline to the snippet? (default: true)
param: bool   $appendNewline  Append a newline to the snippet? (default: false)
return: string PHP source code snippet

getEscape($value = '$value')   X-Ref
Get the current escaper.

param: string $value (default: '$value')
return: string Either a custom callback, or an inline call to `htmlspecialchars`

getFindMethod($id)   X-Ref
Select the appropriate Context `find` method for a given $id.

The return value will be one of `find`, `findDot`, `findAnchoredDot` or `last`.

param: string $id Variable name
return: string `find` method name

getCallable($variable = '$value')   X-Ref
Helper function to compile strict vs lax "is callable" logic.

param: string $variable (default: '$value')
return: string "is callable" logic

flushIndent()   X-Ref
Get the current $indent prefix to write to the buffer.

return: string "$indent . " or ""