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: public function render()
48: {
49: $obLevel = ob_get_level();
50: $panels = array();
51: foreach ($this->panels as $id => $panel) {
52: try {
53: $panels[] = array(
54: 'id' => preg_replace('#[^a-z0-9]+#i', '-', $id),
55: 'tab' => $tab = (string) $panel->getTab(),
56: 'panel' => $tab ? (string) $panel->getPanel() : NULL,
57: );
58: } catch (\Exception $e) {
59: $panels[] = array(
60: 'id' => "error-" . preg_replace('#[^a-z0-9]+#i', '-', $id),
61: 'tab' => "Error in $id",
62: 'panel' => '<h1>Error: ' . $id . '</h1><div class="nette-inner">' . nl2br(htmlSpecialChars($e)) . '</div>',
63: );
64: while (ob_get_level() > $obLevel) {
65: ob_end_clean();
66: }
67: }
68: }
69: require __DIR__ . '/templates/bar.phtml';
70: }
71:
72: }
73: