This repository has been archived by the owner on Jul 11, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
handler.php
66 lines (50 loc) · 1.69 KB
/
handler.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
<?php
// create a blanket method that handles exceptions
set_exception_handler( 'handleExceptions' );
// start output buffering (gzipping if possible)
ob_start( );
// validate class name
$class = strtolower( basename( $_REQUEST[ 'class' ] ) );
if( '' === $class ){ throw new Exception( 'Class name is required' ); }
// validate function name
$func = basename( $_REQUEST[ 'function' ] );
if( '' === $class ){ throw new Exception( 'Class name is required' ); }
// see if file even exists
if( !is_file( 'bridges/class.' . $class . '.php' ) ){ throw new Exception( 'Class does not exist' ); }
// see if we have read access
if( !is_readable( 'bridges/class.' . $class . '.php' ) ){ throw new Exception( 'Bridge file lacks read access' ); }
// include the file, there could exceptions in the code as well...
include_once 'bridges/class.' . $class . '.php';
// check to see if the class has that method
if( !method_exists( $class, $func ) ){ throw new Exception( $class . '::' . $func . ' not found' ); }
// attempt to call the function
echo call_user_func( array( $class, $func ), $_POST[ 'args' ] );
// success, flush output!
ob_end_flush( );
// I think this is easier than a try { } catch ( ){ } block
function handleExceptions( $e )
{
// remove error text
ob_clean( );
// create generic exception
$error = array( "exception" => array( "message" => $e->getMessage( ) ) );
// don't show internal errors
if( __FILE__ !== $e->getFile( ) )
{
$error = array_merge
(
$error,
array
(
"line" => $e->getLine( ),
"file" => $e->getFile( ),
"trace" => $e->getTrace( )
)
);
}
// don't know how long the data will be...
ob_start( );
echo json_encode( $error );
ob_end_flush( );
}
?>