mirror of
https://github.com/smarty-php/smarty.git
synced 2025-08-03 09:54:27 +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
|
* @return string
|
||||||
*/
|
*/
|
||||||
public function insertLocalVariables(): 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(
|
$e = new CompilerException(
|
||||||
$error_text,
|
$error_text,
|
||||||
0,
|
0,
|
||||||
$this->template->getSource()->getFullResourceName(),
|
$this->template->getSource()->getFilepath() ?? $this->template->getSource()->getFullResourceName(),
|
||||||
$line
|
$line
|
||||||
);
|
);
|
||||||
$e->source = trim(preg_replace('![\t\r\n]+!', ' ', $match[$line - 1]));
|
$e->source = trim(preg_replace('![\t\r\n]+!', ' ', $match[$line - 1]));
|
||||||
|
@@ -271,11 +271,11 @@ class Source {
|
|||||||
return $this->type . ':' . $this->name;
|
return $this->type . ':' . $this->name;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getFilepath(): string {
|
public function getFilepath(): ?string {
|
||||||
if ($this->handler instanceof FilePlugin) {
|
if ($this->handler instanceof FilePlugin) {
|
||||||
return $this->handler->getFilePath($this->name, $this->smarty, $this->isConfig);
|
return $this->handler->getFilePath($this->name, $this->smarty, $this->isConfig);
|
||||||
}
|
}
|
||||||
return '.';
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function isConfig(): bool {
|
public function isConfig(): bool {
|
||||||
|
Reference in New Issue
Block a user