Namespaces

  • Nette
    • Application
      • Diagnostics
      • Responses
      • Routers
      • UI
    • Caching
      • Storages
    • ComponentModel
    • Database
      • Diagnostics
      • Drivers
      • Reflection
      • Table
    • DI
      • Config
        • Adapters
      • Diagnostics
      • Extensions
    • Diagnostics
    • Forms
      • Controls
      • Rendering
    • Http
      • Diagnostics
    • Iterators
    • Latte
      • Macros
    • Loaders
    • Localization
    • Mail
    • PhpGenerator
    • Reflection
    • Security
      • Diagnostics
    • Templating
    • Utils
  • NetteModule
  • none

Classes

  • Bar
  • BlueScreen
  • Debugger
  • Dumper
  • FireLogger
  • Helpers
  • Logger
  • OutputDebugger

Interfaces

  • IBarPanel
  • Overview
  • Namespace
  • Class
  • Tree
  • Deprecated
  • Other releases
  • Nette homepage
  1: <?php
  2: 
  3: /**
  4:  * This file is part of the Nette Framework (https://nette.org)
  5:  * Copyright (c) 2004 David Grudl (https://davidgrudl.com)
  6:  */
  7: 
  8: namespace Nette\Diagnostics;
  9: 
 10: use Nette;
 11: 
 12: 
 13: /**
 14:  * Debug Bar.
 15:  *
 16:  * @author     David Grudl
 17:  */
 18: class Bar extends Nette\Object
 19: {
 20:     /** @var array */
 21:     private $panels = array();
 22: 
 23: 
 24:     /**
 25:      * Add custom panel.
 26:      * @param  IBarPanel
 27:      * @param  string
 28:      * @return self
 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:      * Returns panel with given id
 45:      * @param  string
 46:      * @return IBarPanel|NULL
 47:      */
 48:     public function getPanel($id)
 49:     {
 50:         return isset($this->panels[$id]) ? $this->panels[$id] : NULL;
 51:     }
 52: 
 53: 
 54:     /**
 55:      * Renders debug bar.
 56:      * @return void
 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) { // restore ob-level if broken
 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: 
Nette 2.1 API documentation generated by ApiGen 2.8.0