Validate array of rules.
This commit is contained in:
parent
1513023aab
commit
6afc41f65a
@ -108,9 +108,23 @@ 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 (is_array($rule)) {
|
||||||
|
$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) {
|
if (call_user_func([$rule, 'validate'], $params[$key]) === false) {
|
||||||
throw new RuntimeException('Wrong type of ' . $this->method . ' method argument ' . $key . '.');
|
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.');
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user