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

Classes

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

Interfaces

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