Overview

Namespaces

  • Budovy
  • Kdyby
    • BootstrapFormRenderer
      • DI
      • Latte
  • 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
  • Nextras
    • Datagrid
  • None
  • PHP
  • Tester
    • CodeCoverage
    • Runner
      • Output
  • Vodacek
    • Forms
      • Controls
  • WebLoader
    • Filter
    • Nette

Classes

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

Interfaces

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