Validate array of rules.

This commit is contained in:
sc0Vu 2018-01-12 12:11:53 +08:00
parent 1513023aab
commit 6afc41f65a

View File

@ -108,8 +108,22 @@ class EthMethod extends JSONRPC implements IMethod
} }
foreach ($rules as $key => $rule) { foreach ($rules as $key => $rule) {
if (isset($params[$key])) { if (isset($params[$key])) {
if (call_user_func([$rule, 'validate'], $params[$key]) === false) { if (is_array($rule)) {
throw new RuntimeException('Wrong type of ' . $this->method . ' method argument ' . $key . '.'); $isError = true;
foreach ($rule as $r) {
if (call_user_func([$rule, 'validate'], $params[$key]) === true) {
$isError = false;
break;
}
}
if ($isError) {
throw new RuntimeException('Wrong type of ' . $this->method . ' method argument ' . $key . '.');
}
} else {
if (call_user_func([$rule, 'validate'], $params[$key]) === false) {
throw new RuntimeException('Wrong type of ' . $this->method . ' method argument ' . $key . '.');
}
} }
} else { } else {
throw new RuntimeException($this->method . ' method argument ' . $key . ' doesn\'t have default value.'); throw new RuntimeException($this->method . ' method argument ' . $key . ' doesn\'t have default value.');