1: <?php
2:
3: 4: 5: 6: 7: 8: 9: 10: 11:
12:
13:
14:
15: 16: 17: 18: 19: 20:
21: class NDebugBlueScreen extends NObject
22: {
23:
24: private $panels = array();
25:
26:
27:
28: 29: 30: 31: 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: 45: 46: 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: 58: 59: 60: 61: 62:
63: public static function highlightFile($file, $line, $lines = 15, $vars = array())
64: {
65: $source = @file_get_contents($file);
66: if ($source) {
67: return self::highlightPhp($source, $line, $lines, $vars);
68: }
69: }
70:
71:
72:
73: 74: 75: 76: 77: 78: 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];
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) {
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+)( )?</span>#', create_function('$m', 'extract($GLOBALS[0]['.array_push($GLOBALS[0], array('vars'=>$vars)).'-1], EXTR_REFS);
129: return isset($vars[$m[1]])
130: ? \'" title="\' . str_replace(\'"\', \'"\', strip_tags(NDebugHelpers::htmlDump($vars[$m[1]]))) . $m[0]
131: : $m[0];
132: '), $out);
133:
134: return "<pre><div>$out</div></pre>";
135: }
136:
137: }
138: