1: <?php
2:
3: 4: 5: 6:
7:
8: namespace Nette\Bridges\Framework;
9:
10: use Latte;
11: use Nette;
12: use Nette\Framework;
13: use Tracy;
14: use Tracy\BlueScreen;
15: use Tracy\Helpers;
16:
17:
18: 19: 20:
21: class TracyBridge
22: {
23: use Nette\StaticClass;
24:
25: public static function initialize()
26: {
27: $blueScreen = Tracy\Debugger::getBlueScreen();
28:
29: if (class_exists(Nette\Framework::class)) {
30: $version = Framework::VERSION . (Framework::REVISION ? ' (' . Framework::REVISION . ')' : '');
31: Tracy\Debugger::getBar()->getPanel('Tracy:info')->data['Nette Framework'] = $version;
32: $blueScreen->info[] = "Nette Framework $version";
33: }
34:
35: if (class_exists(Tracy\Bridges\Nette\Bridge::class)) {
36: Tracy\Bridges\Nette\Bridge::initialize();
37: return;
38: }
39:
40: $blueScreen->addPanel(function ($e) {
41: if ($e instanceof Latte\CompileException) {
42: return [
43: 'tab' => 'Template',
44: 'panel' => (preg_match('#\n|\?#', $e->sourceName)
45: ? ''
46: : '<p>'
47: . (@is_file($e->sourceName)
48: ? '<b>File:</b> ' . Helpers::editorLink($e->sourceName, $e->sourceLine)
49: : '<b>' . htmlspecialchars($e->sourceName . ($e->sourceLine ? ':' . $e->sourceLine : '')) . '</b>')
50: . '</p>')
51: . '<pre class=code><div>'
52: . BlueScreen::highlightLine(htmlspecialchars($e->sourceCode, ENT_IGNORE, 'UTF-8'), $e->sourceLine)
53: . '</div></pre>',
54: ];
55: }
56: });
57:
58: $blueScreen->addPanel(function ($e) {
59: if (
60: $e instanceof Nette\Neon\Exception
61: && preg_match('#line (\d+)#', $e->getMessage(), $m)
62: && ($trace = Helpers::findTrace($e->getTrace(), 'Nette\Neon\Decoder::decode'))
63: ) {
64: return [
65: 'tab' => 'NEON',
66: 'panel' => ($trace2 = Helpers::findTrace($e->getTrace(), 'Nette\DI\Config\Adapters\NeonAdapter::load'))
67: ? '<p><b>File:</b> ' . Helpers::editorLink($trace2['args'][0], $m[1]) . '</p>'
68: . BlueScreen::highlightFile($trace2['args'][0], $m[1])
69: : BlueScreen::highlightPhp($trace['args'][0], $m[1]),
70: ];
71: }
72: });
73: }
74: }
75: