X-Git-Url: http://git.ithinksw.org/extjs.git/blobdiff_plain/2e847cf21b8ab9d15fa167b315ca5b2fa92638fc..6a7e4474cba9d8be4b2ec445e10f1691f7277c50:/examples/image-organizer/php/router.php diff --git a/examples/image-organizer/php/router.php b/examples/image-organizer/php/router.php index 4f35bb14..c3f8cd54 100644 --- a/examples/image-organizer/php/router.php +++ b/examples/image-organizer/php/router.php @@ -1,101 +1,101 @@ -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 ''; -}else{ - echo json_encode($response); -} +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 ''; +}else{ + echo json_encode($response); +}