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