Index: branches/5.2.x/core/kernel/nparser/nparser.php =================================================================== diff -u -N -r13840 -r14095 --- branches/5.2.x/core/kernel/nparser/nparser.php (.../nparser.php) (revision 13840) +++ branches/5.2.x/core/kernel/nparser/nparser.php (.../nparser.php) (revision 14095) @@ -1,6 +1,6 @@ _btnPhrases['design'] = $this->Application->Phrase('la_btn_EditDesign', false, true); @@ -205,7 +210,13 @@ } if ($this->Level > 0) { - $this->Application->handleError(E_USER_ERROR, 'Unclosed tag opened by '.$this->TagInfo($this->Stack[$this->Level]->Tag), $this->Stack[$this->Level]->Tag['file'], $this->Stack[$this->Level]->Tag['line']); + $error_tag = Array ( + 'file' => $this->Stack[$this->Level]->Tag['file'], + 'line' => $this->Stack[$this->Level]->Tag['line'], + ); + + throw new ParserException('Unclosed tag opened by ' . $this->TagInfo($this->Stack[$this->Level]->Tag), 0, null, $error_tag); + return false; } @@ -237,7 +248,8 @@ { if (!preg_match('/([^_ \t\r\n]*)[_]?([^ \t\r\n]*)[ \t\r\n]*(.*)$$/s', $tag['tag'], $parts)) { // this is virtually impossible, but just in case - $this->Application->handleError(E_USER_ERROR, 'Incorrect tag format: '.$tag['tag'], $tag['file'], $tag['line']); + throw new ParserException('Incorrect tag format: ' . $tag['tag'], 0, null, $tag); + return false; } @@ -283,16 +295,25 @@ foreach ($this->Stack as $instance) { $dump[] = $instance->Tag; } - print_pre($dump); - $this->Application->handleError(E_USER_ERROR, 'Closing tag without an opening: '.$this->TagInfo($tag).' - probably opening tag was removed or nested tags error', $tag['file'], $tag['line']); + + if ( $this->Application->isDebugMode() ) { + $this->Application->Debugger->dumpVars($dump); + } + + $error_msg = 'Closing tag without an opening: ' . $this->TagInfo($tag) . ' - probably opening tag was removed or nested tags error'; + throw new ParserException($error_msg, 0, null, $tag); + return false; } + if ($this->Stack[$this->Level]->Tag['name'] != $tag['name']) { $opening_tag = $this->Stack[$this->Level]->Tag; - $this->Application->handleError(E_USER_ERROR, - 'Closing tag '.$this->TagInfo($tag).' does not match - opening tag at current nesting level ('.$this->TagInfo($opening_tag).' - opened at line '.$opening_tag['line'].')', $tag['file'], $tag['line']); + + $error_msg = ' Closing tag ' . $this->TagInfo($tag) . ' does not match + opening tag at current nesting level + (' . $this->TagInfo($opening_tag) . ' opened at line ' . $opening_tag['line'] . ')'; + throw new ParserException($error_msg, 0, null, $tag); + return false; } @@ -302,7 +323,9 @@ } else { // regular tags - just compile if (!$tag['is_closing']) { - $this->Application->handleError(E_USER_ERROR, 'Tag without a handler: '.$this->TagInfo($tag).' - probably missing <empty /> tag closing', $tag['file'], $tag['line']); + $error_msg = 'Tag without a handler: ' . $this->TagInfo($tag) . ' - probably missing <empty /> tag closing'; + throw new ParserException($error_msg, 0, null, $tag); + return false; } @@ -372,7 +395,9 @@ if ($prefix && strpos($prefix, '$') === false) { $p =& $this->GetProcessor($prefix); if (!is_object($p) || !$p->CheckTag($tag['name'], $tag['prefix'])) { - $this->Application->handleError(E_USER_ERROR, 'Unknown tag: '.$this->TagInfo($tag).' - incorrect tag name or prefix ', $tag['file'], $tag['line']); + $error_msg = 'Unknown tag: ' . $this->TagInfo($tag) . ' - incorrect tag name or prefix'; + throw new ParserException($error_msg, 0, null, $tag); + return false; } } @@ -385,11 +410,7 @@ $pre_parsed = $this->Application->TemplatesCache->GetPreParsed($t); if (!$pre_parsed) { if (!$silent) { - if ($this->Application->isDebugMode()) { - $this->Application->Debugger->appendTrace(); - } - - trigger_error('Cannot include "' . $t . '" - file does not exist', E_USER_ERROR); + throw new ParserException('Cannot include "' . $t . '" - file does not exist'); } return false; @@ -651,11 +672,16 @@ return defined('EDITING_MODE') ? $this->DecorateBlock($ret, $params, true) : $ret; } - if ($this->Application->isDebugMode()) { - $this->Application->Debugger->appendTrace(); - } $trace_results = debug_backtrace(); - $this->Application->handleError(E_USER_ERROR, 'Rendering of undefined element '.$params['name'].'', $trace_results[0]['file'], $trace_results[0]['line']); + + $error_tag = Array ( + 'file' => $trace_results[0]['file'], + 'line' => $trace_results[0]['line'], + ); + + $error_msg = 'Rendering of undefined element ' . $params['name'] . ''; + throw new ParserException($error_msg, 0, null, $error_tag); + return false; } @@ -1038,11 +1064,7 @@ // we know this key, but process it at method beginning } else { - if ($this->Application->isDebugMode()) { - $this->Application->Debugger->appendTrace(); - } - - trigger_error('Unknown key part "' . $key . '" used in "key" parameter of tag.', E_USER_ERROR); + throw new ParserException('Unknown key part "' . $key . '" used in "key" parameter of tag'); } } @@ -1135,4 +1157,17 @@ return $minify_helper->CompressScriptTag($data); } +} + +class ParserException extends Exception { + + public function __construct($message = null, $code = 0, Exception $previous = null, $tag = null) + { + parent::__construct($message, $code, $previous); + + if ( isset($tag) ) { + $this->file = $tag['file']; + $this->line = $tag['line']; + } + } } \ No newline at end of file