Skip to content

Commit

Permalink
Bridge: compatibility with Latte 2.10
Browse files Browse the repository at this point in the history
  • Loading branch information
dg committed Jan 22, 2021
1 parent 7794de6 commit 6f7e1c3
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions src/Bridges/Nette/Bridge.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,11 @@ public static function renderLatteError(?\Throwable $e): ?array
];

} elseif ($e && strpos($file = $e->getFile(), '.latte--')) {
$lines = file($file);
if (preg_match('#// source: (\S+\.latte)#', $lines[1], $m) && @is_file($m[1])) { // @ - may trigger error
$lines = file($file, FILE_IGNORE_NEW_LINES);
if (
preg_match('#/(?:/|\*\*) source: (\S+\.latte)#', $lines[1] ?: $lines[4], $m)
&& @is_file($m[1]) // @ - may trigger error
) {
$templateFile = $m[1];
$templateLine = $e->getLine() && preg_match('#/\* line (\d+) \*/#', $lines[$e->getLine() - 1], $m) ? (int) $m[1] : 0;
return [
Expand All @@ -71,7 +74,7 @@ public static function renderLatteUnknownMacro(?\Throwable $e): ?array
if (
$e instanceof Latte\CompileException
&& @is_file($e->sourceName) // @ - may trigger error
&& (preg_match('#Unknown macro (\{\w+)\}, did you mean (\{\w+)\}\?#A', $e->getMessage(), $m)
&& (preg_match('#Unknown (?:macro|tag) (\{\w+)\}, did you mean (\{\w+)\}\?#A', $e->getMessage(), $m)
|| preg_match('#Unknown attribute (n:\w+), did you mean (n:\w+)\?#A', $e->getMessage(), $m))
) {
return [
Expand Down

0 comments on commit 6f7e1c3

Please sign in to comment.