mirror of
https://github.com/smarty-php/smarty.git
synced 2025-08-02 17:34:26 +02:00
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)
|
@@ -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