1: <?php
2:
3: 4: 5: 6: 7:
8:
9:
10:
11: 12: 13: 14: 15: 16:
17: class NDebugBlueScreen extends NObject
18: {
19:
20: private $panels = array();
21:
22:
23: 24: 25: 26: 27:
28: public function addPanel($panel)
29: {
30: if (!in_array($panel, $this->panels, TRUE)) {
31: $this->panels[] = $panel;
32: }
33: return $this;
34: }
35:
36:
37: 38: 39: 40: 41:
42: public function render(Exception $exception)
43: {
44: $panels = $this->panels;
45: require dirname(__FILE__) . '/templates/bluescreen.phtml';
46: }
47:
48:
49: 50: 51: 52: 53: 54: 55:
56: public static function highlightFile($file, $line, $lines = 15, $vars = array())
57: {
58: $source = @file_get_contents($file);
59: if ($source) {
60: return self::highlightPhp($source, $line, $lines, $vars);
61: }
62: }
63:
64:
65: 66: 67: 68: 69: 70: 71:
72: public static function highlightPhp($source, $line, $lines = 15, $vars = array())
73: {
74: if (function_exists('ini_set')) {
75: ini_set('highlight.comment', '#998; font-style: italic');
76: ini_set('highlight.default', '#000');
77: ini_set('highlight.html', '#06B');
78: ini_set('highlight.keyword', '#D24; font-weight: bold');
79: ini_set('highlight.string', '#080');
80: }
81:
82: $source = str_replace(array("\r\n", "\r"), "\n", $source);
83: $source = explode("\n", highlight_string($source, TRUE));
84: $spans = 1;
85: $out = $source[0];
86: $source = explode('<br />', $source[1]);
87: array_unshift($source, NULL);
88:
89: $start = $i = max(1, $line - floor($lines * 2/3));
90: while (--$i >= 1) {
91: if (preg_match('#.*(</?span[^>]*>)#', $source[$i], $m)) {
92: if ($m[1] !== '</span>') {
93: $spans++; $out .= $m[1];
94: }
95: break;
96: }
97: }
98:
99: $source = array_slice($source, $start, $lines, TRUE);
100: end($source);
101: $numWidth = strlen((string) key($source));
102:
103: foreach ($source as $n => $s) {
104: $spans += substr_count($s, '<span') - substr_count($s, '</span');
105: $s = str_replace(array("\r", "\n"), array('', ''), $s);
106: preg_match_all('#<[^>]+>#', $s, $tags);
107: if ($n == $line) {
108: $out .= sprintf(
109: "<span class='highlight'>%{$numWidth}s: %s\n</span>%s",
110: $n,
111: strip_tags($s),
112: implode('', $tags[0])
113: );
114: } else {
115: $out .= sprintf("<span class='line'>%{$numWidth}s:</span> %s\n", $n, $s);
116: }
117: }
118: $out .= str_repeat('</span>', $spans) . '</code>';
119:
120: $out = preg_replace_callback('#">\$(\w+)( )?</span>#', create_function('$m', 'extract($GLOBALS[0]['.array_push($GLOBALS[0], array('vars'=>$vars)).'-1], EXTR_REFS);
121: return isset($vars[$m[1]])
122: ? \'" title="\' . str_replace(\'"\', \'"\', strip_tags(NDebugHelpers::htmlDump($vars[$m[1]]))) . $m[0]
123: : $m[0];
124: '), $out);
125:
126: return "<pre><div>$out</div></pre>";
127: }
128:
129: }
130: