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