|
9 | 9 |
|
10 | 10 | namespace Tracy\Bridges\Nette; |
11 | 11 |
|
12 | | -use Latte; |
13 | 12 | use Nette; |
14 | 13 | use Tracy; |
15 | 14 | use Tracy\BlueScreen; |
16 | 15 | use Tracy\Helpers; |
17 | 16 |
|
18 | 17 |
|
19 | 18 | /** |
20 | | - * Bridge for NEON & Latte. |
| 19 | + * Bridge for NEON. |
21 | 20 | */ |
22 | 21 | class Bridge |
23 | 22 | { |
24 | 23 | public static function initialize(): void |
25 | 24 | { |
26 | 25 | $blueScreen = Tracy\Debugger::getBlueScreen(); |
27 | | - if (!class_exists(Latte\Bridges\Tracy\BlueScreenPanel::class)) { |
28 | | - $blueScreen->addPanel([self::class, 'renderLatteError']); |
29 | | - $blueScreen->addAction([self::class, 'renderLatteUnknownMacro']); |
30 | | - $blueScreen->addFileGenerator(fn(string $file) => substr($file, -6) === '.latte' |
31 | | - ? "{block content}\n\$END\$" |
32 | | - : null); |
33 | | - Tracy\Debugger::addSourceMapper([self::class, 'mapLatteSourceCode']); |
34 | | - } |
35 | | - |
36 | 26 | $blueScreen->addAction([self::class, 'renderMemberAccessException']); |
37 | 27 | $blueScreen->addPanel([self::class, 'renderNeonError']); |
38 | 28 | } |
39 | 29 |
|
40 | 30 |
|
41 | | - public static function renderLatteError(?\Throwable $e): ?array |
42 | | - { |
43 | | - if ($e instanceof Latte\CompileException && $e->sourceName) { |
44 | | - return [ |
45 | | - 'tab' => 'Template', |
46 | | - 'panel' => (preg_match('#\n|\?#', $e->sourceName) |
47 | | - ? '' |
48 | | - : '<p>' |
49 | | - . (@is_file($e->sourceName) // @ - may trigger error |
50 | | - ? '<b>File:</b> ' . Helpers::editorLink($e->sourceName, $e->sourceLine) |
51 | | - : '<b>' . htmlspecialchars($e->sourceName . ($e->sourceLine ? ':' . $e->sourceLine : '')) . '</b>') |
52 | | - . '</p>') |
53 | | - . BlueScreen::highlightFile($e->sourceCode, $e->sourceLine, 15, false), |
54 | | - ]; |
55 | | - } |
56 | | - |
57 | | - return null; |
58 | | - } |
59 | | - |
60 | | - |
61 | | - public static function renderLatteUnknownMacro(?\Throwable $e): ?array |
62 | | - { |
63 | | - if ( |
64 | | - $e instanceof Latte\CompileException |
65 | | - && $e->sourceName |
66 | | - && @is_file($e->sourceName) // @ - may trigger error |
67 | | - && (preg_match('#Unknown macro (\{\w+)\}, did you mean (\{\w+)\}\?#A', $e->getMessage(), $m) |
68 | | - || preg_match('#Unknown attribute (n:\w+), did you mean (n:\w+)\?#A', $e->getMessage(), $m)) |
69 | | - ) { |
70 | | - return [ |
71 | | - 'link' => Helpers::editorUri($e->sourceName, $e->sourceLine, 'fix', $m[1], $m[2]), |
72 | | - 'label' => 'fix it', |
73 | | - ]; |
74 | | - } |
75 | | - |
76 | | - return null; |
77 | | - } |
78 | | - |
79 | | - |
80 | | - /** @return array{file: string, line: int, label: string, active: bool} */ |
81 | | - public static function mapLatteSourceCode(string $file, int $line): ?array |
82 | | - { |
83 | | - if (!strpos($file, '.latte--')) { |
84 | | - return null; |
85 | | - } |
86 | | - |
87 | | - $lines = file($file); |
88 | | - if ( |
89 | | - !preg_match('#^/(?:\*\*|/) source: (\S+\.latte)#m', implode('', array_slice($lines, 0, 10)), $m) |
90 | | - || !@is_file($m[1]) // @ - may trigger error |
91 | | - ) { |
92 | | - return null; |
93 | | - } |
94 | | - |
95 | | - $file = $m[1]; |
96 | | - $line = $line && preg_match('#/\* line (\d+) \*/#', $lines[$line - 1], $m) ? (int) $m[1] : 0; |
97 | | - return ['file' => $file, 'line' => $line, 'label' => 'Latte', 'active' => true]; |
98 | | - } |
99 | | - |
100 | | - |
101 | 31 | public static function renderMemberAccessException(?\Throwable $e): ?array |
102 | 32 | { |
103 | 33 | if (!$e instanceof Nette\MemberAccessException && !$e instanceof \LogicException) { |
|
0 commit comments