forked from Scriptor/pharen
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtemplate_debug.php
41 lines (36 loc) · 1.22 KB
/
template_debug.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
<?php
namespace pharen\debug;
if(!function_exists("pharen\\debug\\convert_line_num")){
function convert_line_num($line_map, $errline){
$pharen_line = 1;
foreach($line_map as $php_line=>$ph_line){
if($php_line > $errline){
break;
}
$pharen_line = $ph_line;
}
return $pharen_line;
}
}
if(!function_exists("pharen\\debug\\generate_pharen_err")){
function generate_pharen_err($msg, $file, $line, $php_line){
echo "Error: $msg near $file:$line\n";
return True;
}
}
if(!function_exists("pharen\\debug\\error_handler")){
function error_handler($errno, $errstr, $errfile, $errline, $errctx){
$line_map = get_line_map($errfile);
$pharen_file = basename($errfile, ".php").".phn";
$pharen_line = convert_line_num($line_map, $errline);
return generate_pharen_err($errstr, $pharen_file, $pharen_line, $errfile, $errline);
}
}
if(!function_exists("pharen\\debug\\get_line_map")){
function get_line_map($file){
$dir = dirname($file);
$base = basename($file, ".php");
return include($dir."/".$base.".linemap.php");
}
}
set_error_handler('pharen\debug\error_handler');