Page MenuHomePhorge

No OneTemporary

diff --git a/src/applications/conduit/call/ConduitCall.php b/src/applications/conduit/call/ConduitCall.php
index 612633dc96..ddd3de8ee6 100644
--- a/src/applications/conduit/call/ConduitCall.php
+++ b/src/applications/conduit/call/ConduitCall.php
@@ -1,96 +1,104 @@
<?php
/**
* Run a conduit method in-process, without requiring HTTP requests. Usage:
*
* $call = new ConduitCall('method.name', array('param' => 'value'));
* $call->setUser($user);
* $result = $call->execute();
*
*/
final class ConduitCall {
private $method;
- private $params;
private $request;
private $user;
public function __construct($method, array $params) {
$this->method = $method;
- $this->params = $params;
$this->handler = $this->buildMethodHandler($method);
+
+ $invalid_params = array_diff_key(
+ $params,
+ $this->handler->defineParamTypes());
+ if ($invalid_params) {
+ throw new ConduitException(
+ "Method '{$method}' doesn't define these parameters: '" .
+ implode("', '", array_keys($invalid_params)) . "'.");
+ }
+
$this->request = new ConduitAPIRequest($params);
}
public function setUser(PhabricatorUser $user) {
$this->user = $user;
return $this;
}
public function getUser() {
return $this->user;
}
public function shouldRequireAuthentication() {
return $this->handler->shouldRequireAuthentication();
}
public function shouldAllowUnguardedWrites() {
return $this->handler->shouldAllowUnguardedWrites();
}
public function getRequiredScope() {
return $this->handler->getRequiredScope();
}
public function getErrorDescription($code) {
return $this->handler->getErrorDescription($code);
}
public function execute() {
if (!$this->getUser()) {
if ($this->shouldRequireAuthentication()) {
throw new ConduitException("ERR-INVALID-AUTH");
}
} else {
$this->request->setUser($this->getUser());
}
return $this->handler->executeMethod($this->request);
}
protected function buildMethodHandler($method) {
$method_class = ConduitAPIMethod::getClassNameFromAPIMethodName($method);
// Test if the method exists.
$ok = false;
try {
$ok = class_exists($method_class);
} catch (Exception $ex) {
// Discard, we provide a more specific exception below.
}
if (!$ok) {
throw new ConduitException(
"Conduit method '{$method}' does not exist.");
}
$class_info = new ReflectionClass($method_class);
if ($class_info->isAbstract()) {
throw new ConduitException(
"Method '{$method}' is not valid; the implementation is an abstract ".
"base class.");
}
$method = newv($method_class, array());
if (!($method instanceof ConduitAPIMethod)) {
throw new ConduitException(
"Method '{$method}' is not valid; the implementation must be ".
"a subclass of ConduitAPIMethod.");
}
return $method;
}
}

File Metadata

Mime Type
text/x-diff
Expires
Sun, Jan 19, 19:41 (1 w, 3 d ago)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
1128069
Default Alt Text
(2 KB)

Event Timeline