From 6afc41f65aac50e1b251ac3fcbf86bfef11afd8c Mon Sep 17 00:00:00 2001 From: sc0Vu Date: Fri, 12 Jan 2018 12:11:53 +0800 Subject: [PATCH] Validate array of rules. --- src/Methods/EthMethod.php | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/src/Methods/EthMethod.php b/src/Methods/EthMethod.php index 82ad760..ca11ce7 100644 --- a/src/Methods/EthMethod.php +++ b/src/Methods/EthMethod.php @@ -108,8 +108,22 @@ class EthMethod extends JSONRPC implements IMethod } foreach ($rules as $key => $rule) { if (isset($params[$key])) { - if (call_user_func([$rule, 'validate'], $params[$key]) === false) { - throw new RuntimeException('Wrong type of ' . $this->method . ' method argument ' . $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) { + throw new RuntimeException('Wrong type of ' . $this->method . ' method argument ' . $key . '.'); + } } } else { throw new RuntimeException($this->method . ' method argument ' . $key . ' doesn\'t have default value.');