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