Namespaces

  • Latte
    • Loaders
    • Macros
    • Runtime
  • Nette
    • Application
      • Responses
      • Routers
      • UI
    • Bridges
      • ApplicationDI
      • ApplicationLatte
      • ApplicationTracy
      • CacheDI
      • CacheLatte
      • DatabaseDI
      • DatabaseTracy
      • DITracy
      • FormsDI
      • FormsLatte
      • Framework
      • HttpDI
      • HttpTracy
      • MailDI
      • ReflectionDI
      • SecurityDI
      • SecurityTracy
    • Caching
      • Storages
    • ComponentModel
    • Database
      • Conventions
      • Drivers
      • Reflection
      • Table
    • DI
      • Config
        • Adapters
      • Extensions
    • Forms
      • Controls
      • Rendering
    • Http
    • Iterators
    • Loaders
    • Localization
    • Mail
    • Neon
    • PhpGenerator
    • Reflection
    • Security
    • Utils
  • none
  • Tracy
    • Bridges
      • Nette

Classes

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

Interfaces

  • IBarPanel
  • ILogger
  • Overview
  • Namespace
  • Class
  • Tree
  • Deprecated
  • Other releases
  • Nette homepage
 1: <?php
 2: 
 3: /**
 4:  * This file is part of the Tracy (https://tracy.nette.org)
 5:  * Copyright (c) 2004 David Grudl (https://davidgrudl.com)
 6:  */
 7: 
 8: namespace Tracy;
 9: 
10: 
11: /**
12:  * Debugger for outputs.
13:  */
14: class OutputDebugger
15: {
16:     const BOM = "\xEF\xBB\xBF";
17: 
18:     /** @var array of [file, line, output, stack] */
19:     private $list = array();
20: 
21: 
22:     public static function enable()
23:     {
24:         $me = new static;
25:         $me->start();
26:     }
27: 
28: 
29:     public function start()
30:     {
31:         foreach (get_included_files() as $file) {
32:             if (fread(fopen($file, 'r'), 3) === self::BOM) {
33:                 $this->list[] = array($file, 1, self::BOM);
34:             }
35:         }
36:         ob_start(array($this, 'handler'), PHP_VERSION_ID >= 50400 ? 1 : 2);
37:     }
38: 
39: 
40:     /** @internal */
41:     public function handler($s, $phase)
42:     {
43:         $trace = debug_backtrace(PHP_VERSION_ID >= 50306 ? DEBUG_BACKTRACE_IGNORE_ARGS : FALSE);
44:         if (isset($trace[0]['file'], $trace[0]['line'])) {
45:             $stack = $trace;
46:             unset($stack[0]['line'], $stack[0]['args']);
47:             $i = count($this->list);
48:             if ($i && $this->list[$i - 1][3] === $stack) {
49:                 $this->list[$i - 1][2] .= $s;
50:             } else {
51:                 $this->list[] = array($trace[0]['file'], $trace[0]['line'], $s, $stack);
52:             }
53:         }
54:         if ($phase === PHP_OUTPUT_HANDLER_FINAL) {
55:             return $this->renderHtml();
56:         }
57:     }
58: 
59: 
60:     private function renderHtml()
61:     {
62:         $res = '<style>code, pre {white-space:nowrap} a {text-decoration:none} pre {color:gray;display:inline} big {color:red}</style><code>';
63:         foreach ($this->list as $item) {
64:             $stack = array();
65:             foreach (array_slice($item[3], 1) as $t) {
66:                 $t += array('class' => '', 'type' => '', 'function' => '');
67:                 $stack[] = "$t[class]$t[type]$t[function]()"
68:                     . (isset($t['file'], $t['line']) ? ' in ' . basename($t['file']) . ":$t[line]" : '');
69:             }
70: 
71:             $res .= Helpers::editorLink($item[0], $item[1]) . ' '
72:                 . '<span title="' . htmlspecialchars(implode("\n", $stack), ENT_IGNORE | ENT_QUOTES, 'UTF-8') . '">'
73:                 . str_replace(self::BOM, '<big>BOM</big>', Dumper::toHtml($item[2]))
74:                 . "</span><br>\n";
75:         }
76:         return $res . '</code>';
77:     }
78: 
79: }
80: 
Nette 2.3-20161221 API API documentation generated by ApiGen 2.8.0