|
@@ -28,6 +28,11 @@ class Mustache_Engine
|
|
|
|
|
|
|
|
const PRAGMA_FILTERS = 'FILTERS';
|
|
const PRAGMA_FILTERS = 'FILTERS';
|
|
|
|
|
|
|
|
|
|
+ // Known pragmas
|
|
|
|
|
+ private static $knownPragmas = array(
|
|
|
|
|
+ self::PRAGMA_FILTERS => true,
|
|
|
|
|
+ );
|
|
|
|
|
+
|
|
|
// Template cache
|
|
// Template cache
|
|
|
private $templates = array();
|
|
private $templates = array();
|
|
|
|
|
|
|
@@ -44,6 +49,7 @@ class Mustache_Engine
|
|
|
private $charset = 'UTF-8';
|
|
private $charset = 'UTF-8';
|
|
|
private $logger;
|
|
private $logger;
|
|
|
private $strictCallables = false;
|
|
private $strictCallables = false;
|
|
|
|
|
+ private $pragmas = array();
|
|
|
|
|
|
|
|
// Services
|
|
// Services
|
|
|
private $tokenizer;
|
|
private $tokenizer;
|
|
@@ -110,6 +116,10 @@ class Mustache_Engine
|
|
|
* // helps protect against arbitrary code execution when user input is passed directly into the template.
|
|
* // 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.
|
|
* // This currently defaults to false, but will default to true in v3.0.
|
|
|
* 'strict_callables' => true,
|
|
* 'strict_callables' => true,
|
|
|
|
|
+ *
|
|
|
|
|
+ * // Enable pragmas across all templates, regardless of the presence of pragma tags in the individual
|
|
|
|
|
+ * // templates.
|
|
|
|
|
+ * 'pragmas' => [Mustache_Engine::PRAGMA_FILTERS],
|
|
|
* );
|
|
* );
|
|
|
*
|
|
*
|
|
|
* @throws Mustache_Exception_InvalidArgumentException If `escape` option is not callable.
|
|
* @throws Mustache_Exception_InvalidArgumentException If `escape` option is not callable.
|
|
@@ -176,6 +186,15 @@ class Mustache_Engine
|
|
|
if (isset($options['strict_callables'])) {
|
|
if (isset($options['strict_callables'])) {
|
|
|
$this->strictCallables = $options['strict_callables'];
|
|
$this->strictCallables = $options['strict_callables'];
|
|
|
}
|
|
}
|
|
|
|
|
+
|
|
|
|
|
+ if (isset($options['pragmas'])) {
|
|
|
|
|
+ foreach ($options['pragmas'] as $pragma) {
|
|
|
|
|
+ if (!isset(self::$knownPragmas[$pragma])) {
|
|
|
|
|
+ throw new Mustache_Exception_InvalidArgumentException(sprintf('Unknown pragma: "%s".', $pragma));
|
|
|
|
|
+ }
|
|
|
|
|
+ $this->pragmas[$pragma] = true;
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
@@ -226,6 +245,16 @@ class Mustache_Engine
|
|
|
return $this->charset;
|
|
return $this->charset;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ /**
|
|
|
|
|
+ * Get the current globally enabled pragmas.
|
|
|
|
|
+ *
|
|
|
|
|
+ * @return array
|
|
|
|
|
+ */
|
|
|
|
|
+ public function getPragmas()
|
|
|
|
|
+ {
|
|
|
|
|
+ return array_keys($this->pragmas);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
/**
|
|
/**
|
|
|
* Set the Mustache template Loader instance.
|
|
* Set the Mustache template Loader instance.
|
|
|
*
|
|
*
|
|
@@ -563,12 +592,13 @@ class Mustache_Engine
|
|
|
public function getTemplateClassName($source)
|
|
public function getTemplateClassName($source)
|
|
|
{
|
|
{
|
|
|
return $this->templateClassPrefix . md5(sprintf(
|
|
return $this->templateClassPrefix . md5(sprintf(
|
|
|
- 'version:%s,escape:%s,entity_flags:%i,charset:%s,strict_callables:%s,source:%s',
|
|
|
|
|
|
|
+ 'version:%s,escape:%s,entity_flags:%i,charset:%s,strict_callables:%s,pragmas:%s,source:%s',
|
|
|
self::VERSION,
|
|
self::VERSION,
|
|
|
isset($this->escape) ? 'custom' : 'default',
|
|
isset($this->escape) ? 'custom' : 'default',
|
|
|
$this->entityFlags,
|
|
$this->entityFlags,
|
|
|
$this->charset,
|
|
$this->charset,
|
|
|
$this->strictCallables ? 'true' : 'false',
|
|
$this->strictCallables ? 'true' : 'false',
|
|
|
|
|
+ implode(' ', array_keys($this->pragmas)),
|
|
|
$source
|
|
$source
|
|
|
));
|
|
));
|
|
|
}
|
|
}
|
|
@@ -705,7 +735,10 @@ class Mustache_Engine
|
|
|
*/
|
|
*/
|
|
|
private function parse($source)
|
|
private function parse($source)
|
|
|
{
|
|
{
|
|
|
- return $this->getParser()->parse($this->tokenize($source));
|
|
|
|
|
|
|
+ $parser = $this->getParser();
|
|
|
|
|
+ $parser->setPragmas($this->getPragmas());
|
|
|
|
|
+
|
|
|
|
|
+ return $parser->parse($this->tokenize($source));
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
@@ -728,7 +761,10 @@ class Mustache_Engine
|
|
|
array('className' => $name)
|
|
array('className' => $name)
|
|
|
);
|
|
);
|
|
|
|
|
|
|
|
- return $this->getCompiler()->compile($source, $tree, $name, isset($this->escape), $this->charset, $this->strictCallables, $this->entityFlags);
|
|
|
|
|
|
|
+ $compiler = $this->getCompiler();
|
|
|
|
|
+ $compiler->setPragmas($this->getPragmas());
|
|
|
|
|
+
|
|
|
|
|
+ return $compiler->compile($source, $tree, $name, isset($this->escape), $this->charset, $this->strictCallables, $this->entityFlags);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
/**
|