/
textmate.php
73 lines (68 loc) · 2.57 KB
/
textmate.php
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
<?php
/*
* TextMate support library
* Authors: Ciarán Walsh
*/
/* Since the below functions all rely on txmt:// to be of any use,
* they aren't useful unless you are accessing the same system as the server.
* Perhaps there are more situations to handle (i.e. network mounts)
* But since I don't use them I'll need an example case from someone to implement it
*/
if (isset($_SERVER['REMOTE_ADDR']) && $_SERVER['REMOTE_ADDR'] != '127.0.0.1') return;
/*
* Print the error linking javascript at the end of the page
* If error_get_last() is available (PHP 5 >= 5.2.0) then it is checked
* and javascript will be printed only if there has been an error
*
* If TEXTMATE_NO_ERRORS is defined then the javascript will never be printed
*/
/*
* Print the javascript to parse and link errors
*/
function textmate_print_error_handler() {
@include(dirname(__FILE__) . "/textmate_error_handler.html");
}
/*
* If TEXTMATE_ERRORS is defined then this will set up a shutdown function
* to automatically print the javascript error parser at the end of the page
* If error_get_last() is available (PHP 5 >= 5.2.0) then the javascript
* will be printed only if an error has occured (since printing at the end
* of the page will invalidate it)
*/
if (defined('TEXTMATE_ERRORS')) {
register_shutdown_function(create_function('', '
if (!function_exists("error_get_last") || error_get_last())
textmate_print_error_handler();'
));
}
/*
* textmate_backtrace()
*
* Dumps a backtrace in the same format as debug_print_backtrace(), adding links
* to files & lines using the txmt://open schema
*
* Regexing the output of debug_print_backtrace() would be easier but we can't use
* output buffering in case it's already being used
*/
function textmate_backtrace() {
echo '<pre class="backtrace">';
foreach (debug_backtrace() as $number => $trace) {
echo "#{$number} ";
if (isset($trace['class'])) echo $trace['class'], '::';
echo $trace['function'], '(';
if (isset($trace['args'])) echo implode(', ', $trace['args']);
echo ') called at [';
$file = $line = '';
if (strpos($trace['file'], 'eval') !== false) {
$matches = array();
if (preg_match('/^(.+)\((\d+)\) : eval/', $trace['file'], $matches))
list($dummy, $file, $line) = $matches;
} else {
$file = $trace['file'];
$line = $trace['line'];
}
echo '<a href="txmt://open?url=file://', $file, '&line=', $line, '">', $trace['file'], ':', $trace['line'], "</a>]\n";
}
echo '</pre>';
}
?>