Split section exceptions, variable exceptions and partial exceptions into distinct configuration options.

This commit is contained in:
Justin Hileman
2010-03-22 19:15:46 -04:00
parent d30febdf57
commit c849d351f9
+7 -5
View File
@@ -18,7 +18,9 @@ class Mustache {
public $ctag = '}}'; public $ctag = '}}';
// Should this Mustache throw exceptions when it finds unexpected tags? // Should this Mustache throw exceptions when it finds unexpected tags?
protected $throwExceptions = false; protected $throwSectionExceptions = true;
protected $throwPartialExceptions = false;
protected $throwVariableExceptions = false;
protected $tagRegEx; protected $tagRegEx;
@@ -170,14 +172,14 @@ class Mustache {
protected function renderTag($modifier, $tag_name, &$context) { protected function renderTag($modifier, $tag_name, &$context) {
switch ($modifier) { switch ($modifier) {
case '#': case '#':
if ($this->throwExceptions) { if ($this->throwSectionExceptions) {
throw new MustacheException('Unclosed section: ' . $tag_name, MustacheException::UNCLOSED_SECTION); throw new MustacheException('Unclosed section: ' . $tag_name, MustacheException::UNCLOSED_SECTION);
} else { } else {
return ''; return '';
} }
break; break;
case '/': case '/':
if ($this->throwExceptions) { if ($this->throwSectionExceptions) {
throw new MustacheException('Unexpected close section: ' . $tag_name, MustacheException::UNEXPECTED_CLOSE_SECTION); throw new MustacheException('Unexpected close section: ' . $tag_name, MustacheException::UNEXPECTED_CLOSE_SECTION);
} else { } else {
return ''; return '';
@@ -321,7 +323,7 @@ class Mustache {
} }
} }
if ($this->throwExceptions) { if ($this->throwVariableExceptions) {
throw new MustacheException("Unknown variable: " . $tag_name, MustacheException::UNKNOWN_VARIABLE); throw new MustacheException("Unknown variable: " . $tag_name, MustacheException::UNKNOWN_VARIABLE);
} else { } else {
return ''; return '';
@@ -342,7 +344,7 @@ class Mustache {
return $this->partials[$tag_name]; return $this->partials[$tag_name];
} }
if ($this->throwExceptions) { if ($this->throwPartialExceptions) {
throw new MustacheException('Unknown partial: ' . $tag_name, MustacheException::UNKNOWN_PARTIAL); throw new MustacheException('Unknown partial: ' . $tag_name, MustacheException::UNKNOWN_PARTIAL);
} else { } else {
return ''; return '';