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

  • DebugBar
  • DebugBlueScreen
  • Debugger
  • DebugHelpers
  • FireLogger
  • Logger

Interfaces

  • IBarPanel
  • Overview
  • Package
  • Class
  • Tree
  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 DebugBlueScreen extends Object
 22: {
 23:     /** @var array */
 24:     private $panels = array();
 25: 
 26: 
 27: 
 28:     /**
 29:      * Add custom panel.
 30:      * @param  callable
 31:      * @return DebugBlueScreen  provides a fluent interface
 32:      */
 33:     public function addPanel($panel)
 34:     {
 35:         if (!in_array($panel, $this->panels, TRUE)) {
 36:             $this->panels[] = $panel;
 37:         }
 38:         return $this;
 39:     }
 40: 
 41: 
 42: 
 43:     /**
 44:      * Renders blue screen.
 45:      * @param  Exception
 46:      * @return void
 47:      */
 48:     public function render(Exception $exception)
 49:     {
 50:         $panels = $this->panels;
 51:         require dirname(__FILE__) . '/templates/bluescreen.phtml';
 52:     }
 53: 
 54: 
 55: 
 56:     /**
 57:      * Returns syntax highlighted source code.
 58:      * @param  string
 59:      * @param  int
 60:      * @param  int
 61:      * @return string
 62:      */
 63:     public static function highlightFile($file, $line, $lines = 15, $vars = array())
 64:     {
 65:         $source = @file_get_contents($file); // intentionally @
 66:         if ($source) {
 67:             return self::highlightPhp($source, $line, $lines, $vars);
 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:         $spans = 1;
 93:         $out = $source[0]; // <code><span color=highlight.html>
 94:         $source = explode('<br />', $source[1]);
 95:         array_unshift($source, NULL);
 96: 
 97:         $start = $i = max(1, $line - floor($lines * 2/3));
 98:         while (--$i >= 1) { // find last highlighted block
 99:             if (preg_match('#.*(</?span[^>]*>)#', $source[$i], $m)) {
100:                 if ($m[1] !== '</span>') {
101:                     $spans++; $out .= $m[1];
102:                 }
103:                 break;
104:             }
105:         }
106: 
107:         $source = array_slice($source, $start, $lines, TRUE);
108:         end($source);
109:         $numWidth = strlen((string) key($source));
110: 
111:         foreach ($source as $n => $s) {
112:             $spans += substr_count($s, '<span') - substr_count($s, '</span');
113:             $s = str_replace(array("\r", "\n"), array('', ''), $s);
114:             preg_match_all('#<[^>]+>#', $s, $tags);
115:             if ($n == $line) {
116:                 $out .= sprintf(
117:                     "<span class='highlight'>%{$numWidth}s:    %s\n</span>%s",
118:                     $n,
119:                     strip_tags($s),
120:                     implode('', $tags[0])
121:                 );
122:             } else {
123:                 $out .= sprintf("<span class='line'>%{$numWidth}s:</span>    %s\n", $n, $s);
124:             }
125:         }
126:         $out .= str_repeat('</span>', $spans) . '</code>';
127: 
128:         $out = preg_replace_callback('#">\$(\w+)(&nbsp;)?</span>#', create_function('$m', 'extract(NCFix::$vars['.NCFix::uses(array('vars'=>$vars)).'], EXTR_REFS);
129:             return isset($vars[$m[1]])
130:                 ? \'" title="\' . str_replace(\'"\', \'&quot;\', strip_tags(DebugHelpers::htmlDump($vars[$m[1]]))) . $m[0]
131:                 : $m[0];
132:         '), $out);
133: 
134:         return "<pre><div>$out</div></pre>";
135:     }
136: 
137: }
138: 
Nette Framework 2.0.3 (for PHP 5.2, un-prefixed) API API documentation generated by ApiGen 2.7.0