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 (\Exception $e) {
70: $panels[] = array(
71: 'id' => "error-" . preg_replace('#[^a-z0-9]+#i', '-', $id),
72: 'tab' => "Error in $id",
73: 'panel' => '<h1>Error: ' . $id . '</h1><div class="nette-inner">' . nl2br(htmlSpecialChars($e, ENT_IGNORE)) . '</div>',
74: );
75: while (ob_get_level() > $obLevel) {
76: ob_end_clean();
77: }
78: }
79: }
80:
81: @session_start();
82: $session = & $_SESSION['__NF']['debuggerbar'];
83: if (preg_match('#^Location:#im', implode("\n", headers_list()))) {
84: $session[] = $panels;
85: return;
86: }
87:
88: foreach (array_reverse((array) $session) as $reqId => $oldpanels) {
89: $panels[] = array(
90: 'tab' => '<span title="Previous request before redirect">previous</span>',
91: 'panel' => NULL,
92: 'previous' => TRUE,
93: );
94: foreach ($oldpanels as $panel) {
95: $panel['id'] .= '-' . $reqId;
96: $panels[] = $panel;
97: }
98: }
99: $session = NULL;
100:
101: require __DIR__ . '/templates/bar.phtml';
102: }
103:
104: }
105: