Namespaces

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

Classes

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

Interfaces

  • IBarPanel
  • Overview
  • Namespace
  • Class
  • Tree
  • Deprecated
  1: <?php
  2: 
  3: /**
  4:  * This file is part of the Tracy (http://tracy.nette.org)
  5:  * Copyright (c) 2004 David Grudl (http://davidgrudl.com)
  6:  */
  7: 
  8: namespace Tracy;
  9: 
 10: use Tracy;
 11: 
 12: 
 13: /**
 14:  * Red BlueScreen.
 15:  *
 16:  * @author     David Grudl
 17:  */
 18: class BlueScreen
 19: {
 20:     /** @var string[] */
 21:     public $info = array();
 22: 
 23:     /** @var callable[] */
 24:     private $panels = array();
 25: 
 26:     /** @var string[] paths to be collapsed in stack trace (e.g. core libraries) */
 27:     public $collapsePaths = array(__DIR__);
 28: 
 29: 
 30:     /**
 31:      * Add custom panel.
 32:      * @param  callable
 33:      * @return self
 34:      */
 35:     public function addPanel($panel)
 36:     {
 37:         if (!in_array($panel, $this->panels, TRUE)) {
 38:             $this->panels[] = $panel;
 39:         }
 40:         return $this;
 41:     }
 42: 
 43: 
 44:     /**
 45:      * Renders blue screen.
 46:      * @param  \Exception
 47:      * @return void
 48:      */
 49:     public function render(\Exception $exception)
 50:     {
 51:         $panels = $this->panels;
 52:         $info = array_filter($this->info);
 53:         require __DIR__ . '/templates/bluescreen.phtml';
 54:     }
 55: 
 56: 
 57:     /**
 58:      * Returns syntax highlighted source code.
 59:      * @param  string
 60:      * @param  int
 61:      * @param  int
 62:      * @return string
 63:      */
 64:     public static function highlightFile($file, $line, $lines = 15, array $vars = NULL)
 65:     {
 66:         $source = @file_get_contents($file); // intentionally @
 67:         if ($source) {
 68:             $source = static::highlightPhp($source, $line, $lines, $vars);
 69:             if ($editor = Helpers::editorUri($file, $line)) {
 70:                 $source = substr_replace($source, ' data-tracy-href="' . htmlspecialchars($editor) . '"', 4, 0);
 71:             }
 72:             return $source;
 73:         }
 74:     }
 75: 
 76: 
 77:     /**
 78:      * Returns syntax highlighted source code.
 79:      * @param  string
 80:      * @param  int
 81:      * @param  int
 82:      * @return string
 83:      */
 84:     public static function highlightPhp($source, $line, $lines = 15, array $vars = NULL)
 85:     {
 86:         if (function_exists('ini_set')) {
 87:             ini_set('highlight.comment', '#998; font-style: italic');
 88:             ini_set('highlight.default', '#000');
 89:             ini_set('highlight.html', '#06B');
 90:             ini_set('highlight.keyword', '#D24; font-weight: bold');
 91:             ini_set('highlight.string', '#080');
 92:         }
 93: 
 94:         $source = str_replace(array("\r\n", "\r"), "\n", $source);
 95:         $source = explode("\n", highlight_string($source, TRUE));
 96:         $out = $source[0]; // <code><span color=highlight.html>
 97:         $source = str_replace('<br />', "\n", $source[1]);
 98:         $out .= static::highlightLine($source, $line, $lines);
 99: 
100:         if ($vars) {
101:             $out = preg_replace_callback('#">\$(\w+)(&nbsp;)?</span>#', function($m) use ($vars) {
102:                 return array_key_exists($m[1], $vars)
103:                     ? '" title="' . str_replace('"', '&quot;', trim(strip_tags(Dumper::toHtml($vars[$m[1]])))) . $m[0]
104:                     : $m[0];
105:             }, $out);
106:         }
107: 
108:         return "<pre class='php'><div>$out</div></pre>";
109:     }
110: 
111: 
112: 
113:     /**
114:      * Returns highlighted line in HTML code.
115:      * @return string
116:      */
117:     public static function highlightLine($html, $line, $lines = 15)
118:     {
119:         $source = explode("\n", "\n" . str_replace("\r\n", "\n", $html));
120:         $out = '';
121:         $spans = 1;
122:         $start = $i = max(1, $line - floor($lines * 2/3));
123:         while (--$i >= 1) { // find last highlighted block
124:             if (preg_match('#.*(</?span[^>]*>)#', $source[$i], $m)) {
125:                 if ($m[1] !== '</span>') {
126:                     $spans++;
127:                     $out .= $m[1];
128:                 }
129:                 break;
130:             }
131:         }
132: 
133:         $source = array_slice($source, $start, $lines, TRUE);
134:         end($source);
135:         $numWidth = strlen((string) key($source));
136: 
137:         foreach ($source as $n => $s) {
138:             $spans += substr_count($s, '<span') - substr_count($s, '</span');
139:             $s = str_replace(array("\r", "\n"), array('', ''), $s);
140:             preg_match_all('#<[^>]+>#', $s, $tags);
141:             if ($n == $line) {
142:                 $out .= sprintf(
143:                     "<span class='highlight'>%{$numWidth}s:    %s\n</span>%s",
144:                     $n,
145:                     strip_tags($s),
146:                     implode('', $tags[0])
147:                 );
148:             } else {
149:                 $out .= sprintf("<span class='line'>%{$numWidth}s:</span>    %s\n", $n, $s);
150:             }
151:         }
152:         $out .= str_repeat('</span>', $spans) . '</code>';
153:         return $out;
154:     }
155: 
156: 
157:     /**
158:      * Should a file be collapsed in stack trace?
159:      * @param  string
160:      * @return bool
161:      */
162:     public function isCollapsed($file)
163:     {
164:         foreach ($this->collapsePaths as $path) {
165:             if (strpos(strtr($file, '\\', '/'), strtr("$path/", '\\', '/')) === 0) {
166:                 return TRUE;
167:             }
168:         }
169:         return FALSE;
170:     }
171: 
172: }
173: 
Nette 2.2.2 API API documentation generated by ApiGen 2.8.0