From 8bc3b1558c43a20ba53e4d96413166c5f19a7dd2 Mon Sep 17 00:00:00 2001 From: Woody Gilk Date: Tue, 1 Mar 2011 12:10:28 -0500 Subject: [PATCH] Added $options to constructor, along with _setOptions method to allow setting some options at runtime --- Mustache.php | 34 +++++++++++++++++++++++++++++++++- 1 file changed, 33 insertions(+), 1 deletion(-) diff --git a/Mustache.php b/Mustache.php index 7171acd..96544a1 100644 --- a/Mustache.php +++ b/Mustache.php @@ -116,14 +116,46 @@ class Mustache { * @param string $template (default: null) * @param mixed $view (default: null) * @param array $partials (default: null) + * @param array $options (default: array()) * @return void */ - public function __construct($template = null, $view = null, $partials = null) { + public function __construct($template = null, $view = null, $partials = null, array $options = null) { if ($template !== null) $this->_template = $template; if ($partials !== null) $this->_partials = $partials; if ($view !== null) $this->_context = array($view); + if ($options !== null) $this->_setOptions($options); } + /** + * _setOptions function. + * + * @access protected + * @param array $options + * @return void + */ + protected function _setOptions(array $options) { + if (isset($options['charset'])) { + $this->_charset = $options['charset']; + } + + if (isset($options['delimiters'])) { + $delims = $options['delimiters']; + if (!is_array($delims)) { + $delims = array_map('trim', explode(' ', $delims, 2)); + } + $this->_otag = preg_quote($delims[0]); + $this->_ctag = preg_quote($delims[1]); + } + + if (isset($options['pragmas'])) { + foreach ($pragmas as $pragma_name) { + if (!in_array($pragma_name, $this->_pragmasImplemented)) { + throw new MustacheException('Unknown pragma: ' . $pragma_name, MustacheException::UNKNOWN_PRAGMA); + } + } + $this->_pragmas = $pragmas; + } + } /** * Mustache class clone method. *