Packages

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

Classes

  • NDebugBar
  • NDebugBlueScreen
  • NDebugger
  • NDebugHelpers
  • NFireLogger
  • NLogger

Interfaces

  • IBarPanel
  • Overview
  • Package
  • Class
  • Tree
  • Deprecated
  1: <?php
  2: 
  3: /**
  4:  * This file is part of the Nette Framework (http://nette.org)
  5:  *
  6:  * Copyright (c) 2004 David Grudl (http://davidgrudl.com)
  7:  *
  8:  * For the full copyright and license information, please view
  9:  * the file license.txt that was distributed with this source code.
 10:  * @package Nette\Diagnostics
 11:  */
 12: 
 13: 
 14: 
 15: /**
 16:  * Red BlueScreen.
 17:  *
 18:  * @author     David Grudl
 19:  * @package Nette\Diagnostics
 20:  */
 21: class NDebugBlueScreen extends NObject
 22: {
 23:     /** @var array */
 24:     private $panels = 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 dirname(__FILE__) . '/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 self::highlightPhp($source, $line, $lines, $vars);
 65:         }
 66:     }
 67: 
 68: 
 69:     /**
 70:      * Returns syntax highlighted source code.
 71:      * @param  string
 72:      * @param  int
 73:      * @param  int
 74:      * @return string
 75:      */
 76:     public static function highlightPhp($source, $line, $lines = 15, $vars = array())
 77:     {
 78:         if (function_exists('ini_set')) {
 79:             ini_set('highlight.comment', '#998; font-style: italic');
 80:             ini_set('highlight.default', '#000');
 81:             ini_set('highlight.html', '#06B');
 82:             ini_set('highlight.keyword', '#D24; font-weight: bold');
 83:             ini_set('highlight.string', '#080');
 84:         }
 85: 
 86:         $source = str_replace(array("\r\n", "\r"), "\n", $source);
 87:         $source = explode("\n", highlight_string($source, TRUE));
 88:         $spans = 1;
 89:         $out = $source[0]; // <code><span color=highlight.html>
 90:         $source = explode('<br />', $source[1]);
 91:         array_unshift($source, NULL);
 92: 
 93:         $start = $i = max(1, $line - floor($lines * 2/3));
 94:         while (--$i >= 1) { // find last highlighted block
 95:             if (preg_match('#.*(</?span[^>]*>)#', $source[$i], $m)) {
 96:                 if ($m[1] !== '</span>') {
 97:                     $spans++; $out .= $m[1];
 98:                 }
 99:                 break;
100:             }
101:         }
102: 
103:         $source = array_slice($source, $start, $lines, TRUE);
104:         end($source);
105:         $numWidth = strlen((string) key($source));
106: 
107:         foreach ($source as $n => $s) {
108:             $spans += substr_count($s, '<span') - substr_count($s, '</span');
109:             $s = str_replace(array("\r", "\n"), array('', ''), $s);
110:             preg_match_all('#<[^>]+>#', $s, $tags);
111:             if ($n == $line) {
112:                 $out .= sprintf(
113:                     "<span class='highlight'>%{$numWidth}s:    %s\n</span>%s",
114:                     $n,
115:                     strip_tags($s),
116:                     implode('', $tags[0])
117:                 );
118:             } else {
119:                 $out .= sprintf("<span class='line'>%{$numWidth}s:</span>    %s\n", $n, $s);
120:             }
121:         }
122:         $out .= str_repeat('</span>', $spans) . '</code>';
123: 
124:         $out = preg_replace_callback('#">\$(\w+)(&nbsp;)?</span>#', create_function('$m', 'extract($GLOBALS[0]['.array_push($GLOBALS[0], array('vars'=>$vars)).'-1], EXTR_REFS);
125:             return isset($vars[$m[1]])
126:                 ? \'" title="\' . str_replace(\'"\', \'&quot;\', strip_tags(NDebugHelpers::htmlDump($vars[$m[1]]))) . $m[0]
127:                 : $m[0];
128:         '), $out);
129: 
130:         return "<pre><div>$out</div></pre>";
131:     }
132: 
133: }
134: 
Nette Framework 2.0.13 (for PHP 5.2, prefixed) API API documentation generated by ApiGen 2.8.0