示例#1
0
文件: Batch.php 项目: burtay/bdApi
 public static function doJob($method, $uri, array $params)
 {
     $fc = self::getFc();
     $request = new bdApi_Zend_Controller_Request_Http(XenForo_Link::convertApiUriToAbsoluteUri($uri, true));
     $request->setMethod($method);
     foreach ($params as $key => $value) {
         $request->setParam($key, $value);
     }
     $fc->setRequest($request);
     // routing
     $routeMatch = $fc->getDependencies()->route($request);
     if (!$routeMatch or !$routeMatch->getControllerName()) {
         list($controllerName, $action) = $fc->getDependencies()->getNotFoundErrorRoute();
         $routeMatch->setControllerName($controllerName);
         $routeMatch->setAction($action);
     }
     $response = $fc->dispatch($routeMatch);
     if ($response instanceof XenForo_ControllerResponse_Error) {
         return array('_job_result' => 'error', '_job_error' => $response->errorText);
     } elseif ($response instanceof XenForo_ControllerResponse_Exception) {
         return array('_job_result' => 'error', '_job_error' => $response->getMessage());
     } elseif ($response instanceof XenForo_ControllerResponse_Message) {
         return array('_job_result' => 'message', '_job_message' => $response->message);
     } elseif ($response instanceof XenForo_ControllerResponse_View) {
         return array('_job_result' => 'ok', '_job_response' => $response);
     }
     throw new XenForo_Exception('Unexpected $response occurred.');
 }