summaryrefslogtreecommitdiffstats
path: root/views/_errors/development.html.php
blob: 18654f67d844043693f5c0ff15df9def5c8747d5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
<?php
/**
 * Lithium: the most rad php framework
 *
 * @copyright     Copyright 2011, Union of RAD (http://union-of-rad.org)
 * @license       http://opensource.org/licenses/bsd-license.php The BSD License
 */

use lithium\analysis\Debugger;
use lithium\analysis\Inspector;

$exception = $info['exception'];
$replace = array('&lt;?php', '?&gt;', '<code>', '</code>', "\n");
$context = 5;

/**
 * Set Lithium-esque colors for syntax highlighing.
 */
ini_set('highlight.string', '#4DDB4A');
ini_set('highlight.comment', '#D42AAE');
ini_set('highlight.keyword', '#D42AAE');
ini_set('highlight.default', '#3C96FF');
ini_set('highlight.htm', '#FFFFFF');

$stack = Debugger::trace(array('format' => 'array', 'trace' => $exception->getTrace()));

array_unshift($stack, array(
	'functionRef' => '[exception]',
	'file' => $exception->getFile(),
	'line' => $exception->getLine()
));

?>
<h3>Exception</h3>

<div class="lithium-exception-class">
	<?=get_class($exception);?>

	<?php if ($code = $exception->getCode()): ?>
		<span class="code">(code <?=$code; ?>)</span>
	<?php endif ?>
</div>

<div class="lithium-exception-message"><?=$exception->getMessage(); ?></div>

<h3 id="source">Source</h3>

<div id="sourceCode"></div>

<h3>Stack Trace</h3>

<div class="lithium-stack-trace">
	<ol>
		<?php foreach ($stack as $id => $frame): ?>
			<?php
				$location = "{$frame['file']}: {$frame['line']}";
				$lines = range($frame['line'] - $context, $frame['line'] + $context);
				$code = Inspector::lines($frame['file'], $lines);
			?>
			<li>
				<tt><a href="#source" id="<?=$id; ?>" class="display-source-excerpt">
					<?=$frame['functionRef']; ?>
				</a></tt>
				<div id="sourceCode<?=$id; ?>" style="display: none;">

					<div class="lithium-exception-location">
						<?=$location; ?>
					</div>

					<div class="lithium-code-dump">
						<pre><code><?php
							foreach ($code as $num => $content):
								$numPad = str_pad($num, 3, ' ');
								$content = str_ireplace(array('<?php', '?>'), '', $content);
								$content = highlight_string("<?php {$numPad}{$content} ?>", true);
								$content = str_replace($replace, '', $content);

								if ($frame['line'] === $num):
									?><span class="code-highlight"><?php
								endif;?><?php echo "{$content}\n"; ?><?php
								if ($frame['line'] === $num):
									?></span><?php
								endif;

							endforeach;
						?></code></pre>
					</div>
				</div>
			</li>
		<?php endforeach; ?>
	</ol>
</div>

<script type="text/javascript">
	window.onload = function() {
		var $ = function() { return document.getElementById.apply(document, arguments); };
		var links = document.getElementsByTagName('a');

		for (i = 0; i < links.length; i++) {
			if (links[i].className.indexOf('display-source-excerpt') >= 0) {
				links[i].onclick = function() {
					$('sourceCode').innerHTML = $('sourceCode' + this.id).innerHTML;
				}
			}
		}
		$('sourceCode').innerHTML = $('sourceCode0').innerHTML;
	}
</script>