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

Classes

Interfaces

  • Overview
  • Package
  • 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 (http://davidgrudl.com)
  6:  * @package Nette\Diagnostics
  7:  */
  8: 
  9: 
 10: 
 11: /**
 12:  * Red BlueScreen.
 13:  *
 14:  * @author     David Grudl
 15:  * @package Nette\Diagnostics
 16:  */
 17: class NDebugBlueScreen extends NObject
 18: {
 19:     /** @var array */
 20:     private $panels = array();
 21: 
 22: 
 23:     /**
 24:      * Add custom panel.
 25:      * @param  callable
 26:      * @return self
 27:      */
 28:     public function addPanel($panel)
 29:     {
 30:         if (!in_array($panel, $this->panels, TRUE)) {
 31:             $this->panels[] = $panel;
 32:         }
 33:         return $this;
 34:     }
 35: 
 36: 
 37:     /**
 38:      * Renders blue screen.
 39:      * @param  Exception
 40:      * @return void
 41:      */
 42:     public function render(Exception $exception)
 43:     {
 44:         $panels = $this->panels;
 45:         require dirname(__FILE__) . '/templates/bluescreen.phtml';
 46:     }
 47: 
 48: 
 49:     /**
 50:      * Returns syntax highlighted source code.
 51:      * @param  string
 52:      * @param  int
 53:      * @param  int
 54:      * @return string
 55:      */
 56:     public static function highlightFile($file, $line, $lines = 15, $vars = array())
 57:     {
 58:         $source = @file_get_contents($file); // intentionally @
 59:         if ($source) {
 60:             return self::highlightPhp($source, $line, $lines, $vars);
 61:         }
 62:     }
 63: 
 64: 
 65:     /**
 66:      * Returns syntax highlighted source code.
 67:      * @param  string
 68:      * @param  int
 69:      * @param  int
 70:      * @return string
 71:      */
 72:     public static function highlightPhp($source, $line, $lines = 15, $vars = array())
 73:     {
 74:         if (function_exists('ini_set')) {
 75:             ini_set('highlight.comment', '#998; font-style: italic');
 76:             ini_set('highlight.default', '#000');
 77:             ini_set('highlight.html', '#06B');
 78:             ini_set('highlight.keyword', '#D24; font-weight: bold');
 79:             ini_set('highlight.string', '#080');
 80:         }
 81: 
 82:         $source = str_replace(array("\r\n", "\r"), "\n", $source);
 83:         $source = explode("\n", highlight_string($source, TRUE));
 84:         $spans = 1;
 85:         $out = $source[0]; // <code><span color=highlight.html>
 86:         $source = explode('<br />', $source[1]);
 87:         array_unshift($source, NULL);
 88: 
 89:         $start = $i = max(1, $line - floor($lines * 2/3));
 90:         while (--$i >= 1) { // find last highlighted block
 91:             if (preg_match('#.*(</?span[^>]*>)#', $source[$i], $m)) {
 92:                 if ($m[1] !== '</span>') {
 93:                     $spans++; $out .= $m[1];
 94:                 }
 95:                 break;
 96:             }
 97:         }
 98: 
 99:         $source = array_slice($source, $start, $lines, TRUE);
100:         end($source);
101:         $numWidth = strlen((string) key($source));
102: 
103:         foreach ($source as $n => $s) {
104:             $spans += substr_count($s, '<span') - substr_count($s, '</span');
105:             $s = str_replace(array("\r", "\n"), array('', ''), $s);
106:             preg_match_all('#<[^>]+>#', $s, $tags);
107:             if ($n == $line) {
108:                 $out .= sprintf(
109:                     "<span class='highlight'>%{$numWidth}s:    %s\n</span>%s",
110:                     $n,
111:                     strip_tags($s),
112:                     implode('', $tags[0])
113:                 );
114:             } else {
115:                 $out .= sprintf("<span class='line'>%{$numWidth}s:</span>    %s\n", $n, $s);
116:             }
117:         }
118:         $out .= str_repeat('</span>', $spans) . '</code>';
119: 
120:         $out = preg_replace_callback('#">\$(\w+)(&nbsp;)?</span>#', create_function('$m', 'extract($GLOBALS[0]['.array_push($GLOBALS[0], array('vars'=>$vars)).'-1], EXTR_REFS);
121:             return isset($vars[$m[1]])
122:                 ? \'" title="\' . str_replace(\'"\', \'&quot;\', strip_tags(NDebugHelpers::htmlDump($vars[$m[1]]))) . $m[0]
123:                 : $m[0];
124:         '), $out);
125: 
126:         return "<pre><div>$out</div></pre>";
127:     }
128: 
129: }
130: 
Nette Framework 2.0.18 (for PHP 5.2, prefixed) API documentation generated by ApiGen 2.8.0