Beispiel #1
0
 public static function doJob($method, $uri, array $params)
 {
     if (XenForo_Application::isRegistered('_bdApi_disableBatch') && XenForo_Application::get('_bdApi_disableBatch')) {
         return array('_job_result' => 'error', '_job_error' => 'Batch running has been disabled.');
     }
     $fc = self::getFc();
     $request = new bdApi_Zend_Controller_Request_Http(bdApi_Data_Helper_Core::safeConvertApiUriToAbsoluteUri($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.');
 }