diff options
| author | Hunman <sanyi.exe@gmail.com> | 2022-11-22 21:58:13 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2022-11-22 21:58:13 +0100 |
| commit | 613c5d691c55124ce7119098cbcdf744fd3255ff (patch) | |
| tree | 732d18727ee170a15871c4576deb045464719ea0 /libs | |
| parent | c016895166af23aa37468e7556577e3f7772065c (diff) | |
| download | smarty-613c5d691c55124ce7119098cbcdf744fd3255ff.tar.gz smarty-613c5d691c55124ce7119098cbcdf744fd3255ff.tar.bz2 smarty-613c5d691c55124ce7119098cbcdf744fd3255ff.zip | |
Make SmartyCompilerException play nicer with error handler libraries (#782)
* Make SmartyCompilerException play nicer with error handler libraries
Added a new constructor, which accepts a filename and a line number too
(similar to ErrorException, except no severity parameter)
This way error handlers will display the correct file's correct line as
the source of the exception, instead of the template's line in the
core of the parser (php file)
Kept the __toString() method, but removed $source, $desc, and $template
* Revert the breaking changes
Diffstat (limited to 'libs')
| -rw-r--r-- | libs/sysplugins/smarty_internal_templatecompilerbase.php | 8 | ||||
| -rw-r--r-- | libs/sysplugins/smartycompilerexception.php | 28 |
2 files changed, 34 insertions, 2 deletions
diff --git a/libs/sysplugins/smarty_internal_templatecompilerbase.php b/libs/sysplugins/smarty_internal_templatecompilerbase.php index 545c1e4f..d5c18d31 100644 --- a/libs/sysplugins/smarty_internal_templatecompilerbase.php +++ b/libs/sysplugins/smarty_internal_templatecompilerbase.php @@ -1131,8 +1131,12 @@ abstract class Smarty_Internal_TemplateCompilerBase echo ob_get_clean(); flush(); } - $e = new SmartyCompilerException($error_text); - $e->setLine($line); + $e = new SmartyCompilerException( + $error_text, + 0, + $this->template->source->filepath, + $line + ); $e->source = trim(preg_replace('![\t\r\n]+!', ' ', $match[ $line - 1 ])); $e->desc = $args; $e->template = $this->template->source->filepath; diff --git a/libs/sysplugins/smartycompilerexception.php b/libs/sysplugins/smartycompilerexception.php index 8833aa52..0a0a3235 100644 --- a/libs/sysplugins/smartycompilerexception.php +++ b/libs/sysplugins/smartycompilerexception.php @@ -8,6 +8,33 @@ class SmartyCompilerException extends SmartyException { /** + * The constructor of the exception + * + * @param string $message The Exception message to throw. + * @param int $code The Exception code. + * @param string|null $filename The filename where the exception is thrown. + * @param int|null $line The line number where the exception is thrown. + * @param Throwable|null $previous The previous exception used for the exception chaining. + */ + public function __construct( + string $message = "", + int $code = 0, + ?string $filename = null, + ?int $line = null, + Throwable $previous = null + ) { + parent::__construct($message, $code, $previous); + + // These are optional parameters, should be be overridden only when present! + if ($filename) { + $this->file = $filename; + } + if ($line) { + $this->line = $line; + } + } + + /** * @return string */ public function __toString() @@ -22,6 +49,7 @@ class SmartyCompilerException extends SmartyException { $this->line = $line; } + /** * The template source snippet relating to the error * |
