[20] | 1 | <?php |
---|
[151] | 2 | if ( !$_GET['act'] ) |
---|
| 3 | echo "controller - #0 : invalid action"; |
---|
| 4 | else |
---|
| 5 | { |
---|
| 6 | #$header = getallheaders(); |
---|
| 7 | #if ( !$header['ThreadId'] ) |
---|
| 8 | # echo "controller - #1 : invalid thread id"; |
---|
| 9 | #else |
---|
| 10 | #{ |
---|
| 11 | #header('ThreadId: ' . $header['ThreadId']); |
---|
| 12 | header('ThreadId: ' . $_GET['act']); |
---|
| 13 | list($type, $file, $complement) = explode('.', $_GET['act']); |
---|
| 14 | switch ( $type ) |
---|
| 15 | { |
---|
| 16 | case '$this' : |
---|
| 17 | case '$class' : |
---|
| 18 | case '$obj' : |
---|
| 19 | factory($file, $complement); |
---|
| 20 | break; |
---|
| 21 | case '$file' : |
---|
| 22 | case '$xml' : |
---|
| 23 | case '$js' : |
---|
| 24 | case '$css' : |
---|
| 25 | shop(); |
---|
| 26 | break; |
---|
| 27 | default : echo "controller - #2 : invalid type"; |
---|
| 28 | } |
---|
| 29 | #} |
---|
| 30 | } |
---|
[55] | 31 | |
---|
[151] | 32 | exit(0); |
---|
[55] | 33 | |
---|
[151] | 34 | function factory($class = false, $method = false) |
---|
| 35 | { |
---|
| 36 | if ( !$class || !$method ) |
---|
| 37 | { |
---|
| 38 | echo "controller - #3 : invalid class or method"; |
---|
| 39 | return false; |
---|
| 40 | } |
---|
[55] | 41 | |
---|
[151] | 42 | # Load dinamically class file. |
---|
| 43 | $filename = 'inc/class.'.$class.'.inc.php'; |
---|
| 44 | if ( !file_exists($filename) ) |
---|
| 45 | { |
---|
| 46 | echo "controller - #4 : class not exists"; |
---|
| 47 | return false; |
---|
| 48 | } |
---|
| 49 | require_once $filename; |
---|
[55] | 50 | |
---|
[151] | 51 | # Create new Object (class loaded). |
---|
| 52 | $obj = new $class; |
---|
| 53 | # Prepare parameters for execution. |
---|
[20] | 54 | $params = array(); |
---|
[55] | 55 | |
---|
[151] | 56 | $request_method = $_SERVER['REQUEST_METHOD']; |
---|
| 57 | switch ( $request_method ) |
---|
| 58 | { |
---|
| 59 | case 'GET' : |
---|
| 60 | array_shift($_GET); |
---|
| 61 | $params = $_GET; |
---|
| 62 | break; |
---|
| 63 | case 'POST' : |
---|
| 64 | $params = $_POST; |
---|
| 65 | break; |
---|
| 66 | case 'HEAD' : |
---|
| 67 | case 'PUT' : |
---|
| 68 | default : |
---|
| 69 | echo "controller - #5 : request method not avaible"; |
---|
| 70 | return false; |
---|
[20] | 71 | } |
---|
| 72 | |
---|
[151] | 73 | # if params is not empty, then class method with parameters. |
---|
| 74 | if ( $params ) |
---|
[20] | 75 | $result = $obj -> $method($params); |
---|
[55] | 76 | else |
---|
[20] | 77 | $result = $obj -> $method(); |
---|
[55] | 78 | |
---|
[151] | 79 | printf("%s", $result); |
---|
| 80 | } |
---|
[20] | 81 | |
---|
[151] | 82 | function shop() |
---|
| 83 | { |
---|
| 84 | } |
---|
[20] | 85 | ?> |
---|