Differential D12770 Diff 30708 src/applications/conduit/controller/PhabricatorConduitAPIController.php
Changeset View
Changeset View
Standalone View
Standalone View
src/applications/conduit/controller/PhabricatorConduitAPIController.php
| Show All 15 Lines | final class PhabricatorConduitAPIController | ||||
| public function processRequest() { | public function processRequest() { | ||||
| $time_start = microtime(true); | $time_start = microtime(true); | ||||
| $request = $this->getRequest(); | $request = $this->getRequest(); | ||||
| $method = $this->method; | $method = $this->method; | ||||
| $api_request = null; | $api_request = null; | ||||
| $method_implementation = null; | |||||
| $log = new PhabricatorConduitMethodCallLog(); | $log = new PhabricatorConduitMethodCallLog(); | ||||
| $log->setMethod($method); | $log->setMethod($method); | ||||
| $metadata = array(); | $metadata = array(); | ||||
| $multimeter = MultimeterControl::getInstance(); | $multimeter = MultimeterControl::getInstance(); | ||||
| if ($multimeter) { | if ($multimeter) { | ||||
| $multimeter->setEventContext('api.'.$method); | $multimeter->setEventContext('api.'.$method); | ||||
| } | } | ||||
| try { | try { | ||||
| list($metadata, $params) = $this->decodeConduitParams($request, $method); | list($metadata, $params) = $this->decodeConduitParams($request, $method); | ||||
| $call = new ConduitCall($method, $params); | $call = new ConduitCall($method, $params); | ||||
| $method_implementation = $call->getMethodImplementation(); | |||||
| $result = null; | $result = null; | ||||
| // TODO: The relationship between ConduitAPIRequest and ConduitCall is a | // TODO: The relationship between ConduitAPIRequest and ConduitCall is a | ||||
| // little odd here and could probably be improved. Specifically, the | // little odd here and could probably be improved. Specifically, the | ||||
| // APIRequest is a sub-object of the Call, which does not parallel the | // APIRequest is a sub-object of the Call, which does not parallel the | ||||
| // role of AphrontRequest (which is an indepenent object). | // role of AphrontRequest (which is an indepenent object). | ||||
| // In particular, the setUser() and getUser() existing independently on | // In particular, the setUser() and getUser() existing independently on | ||||
| ▲ Show 20 Lines • Show All 99 Lines • ▼ Show 20 Lines | $response = id(new ConduitAPIResponse()) | ||||
| ->setErrorCode($error_code) | ->setErrorCode($error_code) | ||||
| ->setErrorInfo($error_info); | ->setErrorInfo($error_info); | ||||
| switch ($request->getStr('output')) { | switch ($request->getStr('output')) { | ||||
| case 'human': | case 'human': | ||||
| return $this->buildHumanReadableResponse( | return $this->buildHumanReadableResponse( | ||||
| $method, | $method, | ||||
| $api_request, | $api_request, | ||||
| $response->toDictionary()); | $response->toDictionary(), | ||||
| $method_implementation); | |||||
| case 'json': | case 'json': | ||||
| default: | default: | ||||
| return id(new AphrontJSONResponse()) | return id(new AphrontJSONResponse()) | ||||
| ->setAddJSONShield(false) | ->setAddJSONShield(false) | ||||
| ->setContent($response->toDictionary()); | ->setContent($response->toDictionary()); | ||||
| } | } | ||||
| } | } | ||||
| ▲ Show 20 Lines • Show All 357 Lines • ▼ Show 20 Lines | private function validateAuthenticatedUser( | ||||
| $request->setUser($user); | $request->setUser($user); | ||||
| return null; | return null; | ||||
| } | } | ||||
| private function buildHumanReadableResponse( | private function buildHumanReadableResponse( | ||||
| $method, | $method, | ||||
| ConduitAPIRequest $request = null, | ConduitAPIRequest $request = null, | ||||
| $result = null) { | $result = null, | ||||
| ConduitAPIMethod $method_implementation = null) { | |||||
| $param_rows = array(); | $param_rows = array(); | ||||
| $param_rows[] = array('Method', $this->renderAPIValue($method)); | $param_rows[] = array('Method', $this->renderAPIValue($method)); | ||||
| if ($request) { | if ($request) { | ||||
| foreach ($request->getAllParameters() as $key => $value) { | foreach ($request->getAllParameters() as $key => $value) { | ||||
| $param_rows[] = array( | $param_rows[] = array( | ||||
| $key, | $key, | ||||
| $this->renderAPIValue($value), | $this->renderAPIValue($value), | ||||
| Show All 32 Lines | private function buildHumanReadableResponse( | ||||
| $result_panel->appendChild($result_table); | $result_panel->appendChild($result_table); | ||||
| $method_uri = $this->getApplicationURI('method/'.$method.'/'); | $method_uri = $this->getApplicationURI('method/'.$method.'/'); | ||||
| $crumbs = $this->buildApplicationCrumbs() | $crumbs = $this->buildApplicationCrumbs() | ||||
| ->addTextCrumb($method, $method_uri) | ->addTextCrumb($method, $method_uri) | ||||
| ->addTextCrumb(pht('Call')); | ->addTextCrumb(pht('Call')); | ||||
| $example_panel = null; | |||||
| if ($request && $method_implementation) { | |||||
| $params = $request->getAllParameters(); | |||||
| $example_panel = $this->renderExampleBox( | |||||
| $method_implementation, | |||||
| $params); | |||||
| } | |||||
| return $this->buildApplicationPage( | return $this->buildApplicationPage( | ||||
| array( | array( | ||||
| $crumbs, | $crumbs, | ||||
| $param_panel, | $param_panel, | ||||
| $result_panel, | $result_panel, | ||||
| $example_panel, | |||||
| ), | ), | ||||
| array( | array( | ||||
| 'title' => pht('Method Call Result'), | 'title' => pht('Method Call Result'), | ||||
| )); | )); | ||||
| } | } | ||||
| private function renderAPIValue($value) { | private function renderAPIValue($value) { | ||||
| $json = new PhutilJSON(); | $json = new PhutilJSON(); | ||||
| ▲ Show 20 Lines • Show All 94 Lines • Show Last 20 Lines | |||||