1: <?php
2:
3: 4: 5: 6:
7:
8: namespace Nette\Diagnostics;
9:
10: use Nette;
11:
12:
13: 14: 15: 16: 17:
18: class Bar extends Nette\Object
19: {
20:
21: private $panels = array();
22:
23:
24: 25: 26: 27: 28: 29:
30: public function addPanel(IBarPanel $panel, $id = NULL)
31: {
32: if ($id === NULL) {
33: $c = 0;
34: do {
35: $id = get_class($panel) . ($c++ ? "-$c" : '');
36: } while (isset($this->panels[$id]));
37: }
38: $this->panels[$id] = $panel;
39: return $this;
40: }
41:
42:
43: 44: 45: 46: 47:
48: public function getPanel($id)
49: {
50: return isset($this->panels[$id]) ? $this->panels[$id] : NULL;
51: }
52:
53:
54: 55: 56: 57:
58: public function render()
59: {
60: $obLevel = ob_get_level();
61: $panels = array();
62: foreach ($this->panels as $id => $panel) {
63: try {
64: $panels[] = array(
65: 'id' => preg_replace('#[^a-z0-9]+#i', '-', $id),
66: 'tab' => $tab = (string) $panel->getTab(),
67: 'panel' => $tab ? (string) $panel->getPanel() : NULL,
68: );
69: } catch (\Throwable $e) {
70: } catch (\Exception $e) {
71: }
72: if (isset($e)) {
73: $panels[] = array(
74: 'id' => "error-" . preg_replace('#[^a-z0-9]+#i', '-', $id),
75: 'tab' => "Error in $id",
76: 'panel' => '<h1>Error: ' . $id . '</h1><div class="nette-inner">' . nl2br(htmlSpecialChars($e, ENT_IGNORE)) . '</div>',
77: );
78: while (ob_get_level() > $obLevel) {
79: ob_end_clean();
80: }
81: }
82: }
83:
84: @session_start();
85: $session = & $_SESSION['__NF']['debuggerbar'];
86: if (preg_match('#^Location:#im', implode("\n", headers_list()))) {
87: $session[] = $panels;
88: return;
89: }
90:
91: foreach (array_reverse((array) $session) as $reqId => $oldpanels) {
92: $panels[] = array(
93: 'tab' => '<span title="Previous request before redirect">previous</span>',
94: 'panel' => NULL,
95: 'previous' => TRUE,
96: );
97: foreach ($oldpanels as $panel) {
98: $panel['id'] .= '-' . $reqId;
99: $panels[] = $panel;
100: }
101: }
102: $session = NULL;
103:
104: require __DIR__ . '/templates/bar.phtml';
105: }
106:
107: }
108: