Namespaces

  • 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

  • Bar
  • BlueScreen
  • Debugger
  • FireLogger
  • Helpers
  • Logger

Interfaces

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