Upgrade to ExtJS 3.2.0 - Released 03/30/2010
[extjs.git] / examples / direct / php / router.php
index 4f35bb1..c3f8cd5 100644 (file)
-<?php\r
-require('config.php');\r
-\r
-class BogusAction {\r
-       public $action;\r
-       public $method;\r
-       public $data;\r
-       public $tid;\r
-}\r
-\r
-$isForm = false;\r
-$isUpload = false;\r
-if(isset($HTTP_RAW_POST_DATA)){\r
-       header('Content-Type: text/javascript');\r
-       $data = json_decode($HTTP_RAW_POST_DATA);\r
-}else if(isset($_POST['extAction'])){ // form post\r
-       $isForm = true;\r
-       $isUpload = $_POST['extUpload'] == 'true';\r
-       $data = new BogusAction();\r
-       $data->action = $_POST['extAction'];\r
-       $data->method = $_POST['extMethod'];\r
-    $data->tid = isset($_POST['extTID']) ? $_POST['extTID'] : null; // not set for upload\r
-       $data->data = array($_POST, $_FILES);\r
-}else{\r
-       die('Invalid request.');\r
-}\r
-\r
-function doRpc($cdata){\r
-    global $API;\r
-       try {\r
-               if(!isset($API[$cdata->action])){\r
-                       throw new Exception('Call to undefined action: ' . $cdata->action);\r
-               }\r
-\r
-               $action = $cdata->action;\r
-               $a = $API[$action];\r
-\r
-               doAroundCalls($a['before'], $cdata);\r
-\r
-               $method = $cdata->method;\r
-               $mdef = $a['methods'][$method];\r
-               if(!$mdef){\r
-                       throw new Exception("Call to undefined method: $method on action $action");\r
-               }\r
-               doAroundCalls($mdef['before'], $cdata);\r
-\r
-               $r = array(\r
-                       'type'=>'rpc',\r
-                       'tid'=>$cdata->tid,\r
-                       'action'=>$action,\r
-                       'method'=>$method\r
-               );\r
-\r
-               require_once("classes/$action.php");\r
-               $o = new $action();\r
-\r
-               $params = isset($cdata->data) && is_array($cdata->data) ? $cdata->data : array();\r
-\r
-               $r['result'] = call_user_func_array(array($o, $method), $params);\r
-\r
-               doAroundCalls($mdef['after'], $cdata, $r);\r
-               doAroundCalls($a['after'], $cdata, $r);\r
-       }\r
-       catch(Exception $e){\r
-               $r['type'] = 'exception';\r
-               $r['message'] = $e->getMessage();\r
-               $r['where'] = $e->getTraceAsString();\r
-       }\r
-       return $r;\r
-}\r
-\r
-\r
-function doAroundCalls(&$fns, &$cdata, &$returnData=null){\r
-       if(!$fns){\r
-               return;\r
-       }\r
-       if(is_array($fns)){\r
-               foreach($fns as $f){\r
-                       $f($cdata, $returnData);\r
-               }\r
-       }else{\r
-               $fns($cdata, $returnData);\r
-       }\r
-}\r
-\r
-$response = null;\r
-if(is_array($data)){\r
-       $response = array();\r
-       foreach($data as $d){\r
-               $response[] = doRpc($d);\r
-       }\r
-}else{\r
-       $response = doRpc($data);\r
-}\r
-if($isForm && $isUpload){\r
-       echo '<html><body><textarea>';\r
-       echo json_encode($response);\r
-       echo '</textarea></body></html>';\r
-}else{\r
-       echo json_encode($response);\r
-}\r
+<?php
+require('config.php');
+
+class BogusAction {
+       public $action;
+       public $method;
+       public $data;
+       public $tid;
+}
+
+$isForm = false;
+$isUpload = false;
+if(isset($HTTP_RAW_POST_DATA)){
+       header('Content-Type: text/javascript');
+       $data = json_decode($HTTP_RAW_POST_DATA);
+}else if(isset($_POST['extAction'])){ // form post
+       $isForm = true;
+       $isUpload = $_POST['extUpload'] == 'true';
+       $data = new BogusAction();
+       $data->action = $_POST['extAction'];
+       $data->method = $_POST['extMethod'];
+    $data->tid = isset($_POST['extTID']) ? $_POST['extTID'] : null; // not set for upload
+       $data->data = array($_POST, $_FILES);
+}else{
+       die('Invalid request.');
+}
+
+function doRpc($cdata){
+    global $API;
+       try {
+               if(!isset($API[$cdata->action])){
+                       throw new Exception('Call to undefined action: ' . $cdata->action);
+               }
+
+               $action = $cdata->action;
+               $a = $API[$action];
+
+               doAroundCalls($a['before'], $cdata);
+
+               $method = $cdata->method;
+               $mdef = $a['methods'][$method];
+               if(!$mdef){
+                       throw new Exception("Call to undefined method: $method on action $action");
+               }
+               doAroundCalls($mdef['before'], $cdata);
+
+               $r = array(
+                       'type'=>'rpc',
+                       'tid'=>$cdata->tid,
+                       'action'=>$action,
+                       'method'=>$method
+               );
+
+               require_once("classes/$action.php");
+               $o = new $action();
+
+               $params = isset($cdata->data) && is_array($cdata->data) ? $cdata->data : array();
+
+               $r['result'] = call_user_func_array(array($o, $method), $params);
+
+               doAroundCalls($mdef['after'], $cdata, $r);
+               doAroundCalls($a['after'], $cdata, $r);
+       }
+       catch(Exception $e){
+               $r['type'] = 'exception';
+               $r['message'] = $e->getMessage();
+               $r['where'] = $e->getTraceAsString();
+       }
+       return $r;
+}
+
+
+function doAroundCalls(&$fns, &$cdata, &$returnData=null){
+       if(!$fns){
+               return;
+       }
+       if(is_array($fns)){
+               foreach($fns as $f){
+                       $f($cdata, $returnData);
+               }
+       }else{
+               $fns($cdata, $returnData);
+       }
+}
+
+$response = null;
+if(is_array($data)){
+       $response = array();
+       foreach($data as $d){
+               $response[] = doRpc($d);
+       }
+}else{
+       $response = doRpc($data);
+}
+if($isForm && $isUpload){
+       echo '<html><body><textarea>';
+       echo json_encode($response);
+       echo '</textarea></body></html>';
+}else{
+       echo json_encode($response);
+}