mirror of
https://github.com/smarty-php/smarty.git
synced 2025-08-02 09:24:28 +02:00
Add template path to CompilerException to enable rich debug features (#936)
* Add template path to CompilerException to enable rich debug features Fixes #935
This commit is contained in:
1
changelog/935.md
Normal file
1
changelog/935.md
Normal file
@@ -0,0 +1 @@
|
||||
- Add template path to CompilerException to enable rich debug features [#935](https://github.com/smarty-php/smarty/issues/935)
|
@@ -117,6 +117,7 @@ The following constants have been removed to prevent global side effects.
|
||||
- Smarty now always runs in multibyte mode. Make sure you use the [PHP multibyte extension](https://www.php.net/manual/en/book.mbstring.php) in production for optimal performance.
|
||||
- Generated `<script>` tags lo longer have deprecated `type="text/javascript"` or `language="Javascript"` attributes
|
||||
- Smarty will throw a compiler exception instead of silently ignoring a modifier on a function call, like this: `{include|dot:"x-template-id" file="included.dot.tpl"}`
|
||||
- The ::getFile() method of a CompilerException will now return the full path of the template being compiled, if possible. This used to be 'file:relative_dir/filename.tpl'.
|
||||
|
||||
## Upgrading from v3 to v4
|
||||
|
||||
|
@@ -121,6 +121,6 @@ class CodeFrame
|
||||
* @return string
|
||||
*/
|
||||
public function insertLocalVariables(): string {
|
||||
return '$_smarty_current_dir = ' . var_export(dirname($this->_template->getSource()->getFilepath()), true) . ";\n";
|
||||
return '$_smarty_current_dir = ' . var_export(dirname($this->_template->getSource()->getFilepath() ?? '.'), true) . ";\n";
|
||||
}
|
||||
}
|
||||
|
@@ -848,7 +848,7 @@ class Template extends BaseCompiler {
|
||||
$e = new CompilerException(
|
||||
$error_text,
|
||||
0,
|
||||
$this->template->getSource()->getFullResourceName(),
|
||||
$this->template->getSource()->getFilepath() ?? $this->template->getSource()->getFullResourceName(),
|
||||
$line
|
||||
);
|
||||
$e->source = trim(preg_replace('![\t\r\n]+!', ' ', $match[$line - 1]));
|
||||
|
@@ -271,11 +271,11 @@ class Source {
|
||||
return $this->type . ':' . $this->name;
|
||||
}
|
||||
|
||||
public function getFilepath(): string {
|
||||
public function getFilepath(): ?string {
|
||||
if ($this->handler instanceof FilePlugin) {
|
||||
return $this->handler->getFilePath($this->name, $this->smarty, $this->isConfig);
|
||||
}
|
||||
return '.';
|
||||
return null;
|
||||
}
|
||||
|
||||
public function isConfig(): bool {
|
||||
|
Reference in New Issue
Block a user