From 6f7e1c350397dab896c4e5d92438a8534907d328 Mon Sep 17 00:00:00 2001 From: David Grudl Date: Sat, 23 Jan 2021 00:09:37 +0100 Subject: [PATCH] Bridge: compatibility with Latte 2.10 --- src/Bridges/Nette/Bridge.php | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/Bridges/Nette/Bridge.php b/src/Bridges/Nette/Bridge.php index 2fe97b23d..f6ef293c1 100644 --- a/src/Bridges/Nette/Bridge.php +++ b/src/Bridges/Nette/Bridge.php @@ -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 [ @@ -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 [