Differential D16694 Diff 40224 src/applications/conduit/controller/PhabricatorConduitAPIController.php
Changeset View
Changeset View
Standalone View
Standalone View
src/applications/conduit/controller/PhabricatorConduitAPIController.php
Show All 19 Lines | public function handleRequest(AphrontRequest $request) { | ||||
$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, $strictly_typed) = $this->decodeConduitParams( | ||||
$request, | |||||
$method); | |||||
$call = new ConduitCall($method, $params); | $call = new ConduitCall($method, $params, $strictly_typed); | ||||
$method_implementation = $call->getMethodImplementation(); | $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). | ||||
▲ Show 20 Lines • Show All 594 Lines • ▼ Show 20 Lines | if ($params !== null) { | ||||
$value)); | $value)); | ||||
} | } | ||||
$params[$key] = $decoded_value; | $params[$key] = $decoded_value; | ||||
} | } | ||||
$metadata = idx($params, '__conduit__', array()); | $metadata = idx($params, '__conduit__', array()); | ||||
unset($params['__conduit__']); | unset($params['__conduit__']); | ||||
return array($metadata, $params); | return array($metadata, $params, true); | ||||
} | } | ||||
// Otherwise, look for a single parameter called 'params' which has the | // Otherwise, look for a single parameter called 'params' which has the | ||||
// entire param dictionary JSON encoded. | // entire param dictionary JSON encoded. | ||||
$params_json = $request->getStr('params'); | $params_json = $request->getStr('params'); | ||||
if (strlen($params_json)) { | if (strlen($params_json)) { | ||||
$params = null; | $params = null; | ||||
try { | try { | ||||
$params = phutil_json_decode($params_json); | $params = phutil_json_decode($params_json); | ||||
} catch (PhutilJSONParserException $ex) { | } catch (PhutilJSONParserException $ex) { | ||||
throw new PhutilProxyException( | throw new PhutilProxyException( | ||||
pht( | pht( | ||||
"Invalid parameter information was passed to method '%s'.", | "Invalid parameter information was passed to method '%s'.", | ||||
$method), | $method), | ||||
$ex); | $ex); | ||||
} | } | ||||
$metadata = idx($params, '__conduit__', array()); | $metadata = idx($params, '__conduit__', array()); | ||||
unset($params['__conduit__']); | unset($params['__conduit__']); | ||||
return array($metadata, $params); | return array($metadata, $params, true); | ||||
} | } | ||||
// If we do not have `params`, assume this is a simple HTTP request with | // If we do not have `params`, assume this is a simple HTTP request with | ||||
// HTTP key-value pairs. | // HTTP key-value pairs. | ||||
$params = array(); | $params = array(); | ||||
$metadata = array(); | $metadata = array(); | ||||
foreach ($request->getPassthroughRequestData() as $key => $value) { | foreach ($request->getPassthroughRequestData() as $key => $value) { | ||||
$meta_key = ConduitAPIMethod::getParameterMetadataKey($key); | $meta_key = ConduitAPIMethod::getParameterMetadataKey($key); | ||||
if ($meta_key !== null) { | if ($meta_key !== null) { | ||||
$metadata[$meta_key] = $value; | $metadata[$meta_key] = $value; | ||||
} else { | } else { | ||||
$params[$key] = $value; | $params[$key] = $value; | ||||
} | } | ||||
} | } | ||||
return array($metadata, $params); | return array($metadata, $params, false); | ||||
} | } | ||||
private function authorizeOAuthMethodAccess( | private function authorizeOAuthMethodAccess( | ||||
PhabricatorOAuthClientAuthorization $authorization, | PhabricatorOAuthClientAuthorization $authorization, | ||||
$method_name) { | $method_name) { | ||||
$method = ConduitAPIMethod::getConduitMethod($method_name); | $method = ConduitAPIMethod::getConduitMethod($method_name); | ||||
if (!$method) { | if (!$method) { | ||||
Show All 21 Lines |