From 15506cc2b2d7ec80e24eb6f15fa77a989c05f037 Mon Sep 17 00:00:00 2001 From: sc0Vu Date: Tue, 9 Jan 2018 17:53:16 +0800 Subject: [PATCH] Net api methods. --- src/Methods/Net/Listening.php | 88 +++++++++++++++++++++++++++++++++++ src/Methods/Net/PeerCount.php | 88 +++++++++++++++++++++++++++++++++++ src/Methods/Net/Version.php | 88 +++++++++++++++++++++++++++++++++++ 3 files changed, 264 insertions(+) create mode 100644 src/Methods/Net/Listening.php create mode 100644 src/Methods/Net/PeerCount.php create mode 100644 src/Methods/Net/Version.php diff --git a/src/Methods/Net/Listening.php b/src/Methods/Net/Listening.php new file mode 100644 index 0000000..94139f3 --- /dev/null +++ b/src/Methods/Net/Listening.php @@ -0,0 +1,88 @@ + + * + * @author Peter Lai + * @license MIT + */ + +namespace Web3\Methods\Net; + +use InvalidArgumentException; +use Web3\Methods\IMethod; +use Web3\Methods\JSONRPC; + +class Listening extends JSONRPC implements IMethod +{ + /** + * inputFormatters + * + * @var array + */ + protected $inputFormatters = []; + + /** + * outputFormatters + * + * @var array + */ + protected $outputFormatters = []; + + /** + * construct + * + * @param string $method + * @param array $arguments + * @return void + */ + // public function __construct($method='', $arguments=[]) + // { + // parent::__construct($method, $arguments); + // } + + /** + * getInputFormatters + * + * @return array + */ + public function getInputFormatters() + { + return $this->inputFormatters; + } + + /** + * getOutputFormatters + * + * @return array + */ + public function getOutputFormatters() + { + return $this->outputFormatters; + } + + /** + * transform + * + * @param array $params + * @param array $rules + * @return array + */ + public function transform($params, $rules) + { + if (!is_array($params)) { + throw new InvalidArgumentException('Please use array params when call transform.'); + } + if (!is_array($rules)) { + throw new InvalidArgumentException('Please use array rules when call transform.'); + } + foreach ($params as $key => $param) { + if (isset($rules[$key])) { + $params[$key] = call_user_func([$rules[$key], 'format'], $param); + } + } + return $params; + } +} \ No newline at end of file diff --git a/src/Methods/Net/PeerCount.php b/src/Methods/Net/PeerCount.php new file mode 100644 index 0000000..b021576 --- /dev/null +++ b/src/Methods/Net/PeerCount.php @@ -0,0 +1,88 @@ + + * + * @author Peter Lai + * @license MIT + */ + +namespace Web3\Methods\Net; + +use InvalidArgumentException; +use Web3\Methods\IMethod; +use Web3\Methods\JSONRPC; + +class PeerCount extends JSONRPC implements IMethod +{ + /** + * inputFormatters + * + * @var array + */ + protected $inputFormatters = []; + + /** + * outputFormatters + * + * @var array + */ + protected $outputFormatters = []; + + /** + * construct + * + * @param string $method + * @param array $arguments + * @return void + */ + // public function __construct($method='', $arguments=[]) + // { + // parent::__construct($method, $arguments); + // } + + /** + * getInputFormatters + * + * @return array + */ + public function getInputFormatters() + { + return $this->inputFormatters; + } + + /** + * getOutputFormatters + * + * @return array + */ + public function getOutputFormatters() + { + return $this->outputFormatters; + } + + /** + * transform + * + * @param array $params + * @param array $rules + * @return array + */ + public function transform($params, $rules) + { + if (!is_array($params)) { + throw new InvalidArgumentException('Please use array params when call transform.'); + } + if (!is_array($rules)) { + throw new InvalidArgumentException('Please use array rules when call transform.'); + } + foreach ($params as $key => $param) { + if (isset($rules[$key])) { + $params[$key] = call_user_func([$rules[$key], 'format'], $param); + } + } + return $params; + } +} \ No newline at end of file diff --git a/src/Methods/Net/Version.php b/src/Methods/Net/Version.php new file mode 100644 index 0000000..9abc5ae --- /dev/null +++ b/src/Methods/Net/Version.php @@ -0,0 +1,88 @@ + + * + * @author Peter Lai + * @license MIT + */ + +namespace Web3\Methods\Net; + +use InvalidArgumentException; +use Web3\Methods\IMethod; +use Web3\Methods\JSONRPC; + +class Version extends JSONRPC implements IMethod +{ + /** + * inputFormatters + * + * @var array + */ + protected $inputFormatters = []; + + /** + * outputFormatters + * + * @var array + */ + protected $outputFormatters = []; + + /** + * construct + * + * @param string $method + * @param array $arguments + * @return void + */ + // public function __construct($method='', $arguments=[]) + // { + // parent::__construct($method, $arguments); + // } + + /** + * getInputFormatters + * + * @return array + */ + public function getInputFormatters() + { + return $this->inputFormatters; + } + + /** + * getOutputFormatters + * + * @return array + */ + public function getOutputFormatters() + { + return $this->outputFormatters; + } + + /** + * transform + * + * @param array $params + * @param array $rules + * @return array + */ + public function transform($params, $rules) + { + if (!is_array($params)) { + throw new InvalidArgumentException('Please use array params when call transform.'); + } + if (!is_array($rules)) { + throw new InvalidArgumentException('Please use array rules when call transform.'); + } + foreach ($params as $key => $param) { + if (isset($rules[$key])) { + $params[$key] = call_user_func([$rules[$key], 'format'], $param); + } + } + return $params; + } +} \ No newline at end of file