From 8d1512a51a43263889dd4467f7d21549c2254a1d Mon Sep 17 00:00:00 2001 From: Alexander Korelskiy Date: Mon, 5 Apr 2021 15:04:15 +0300 Subject: [PATCH] Fix classes autoloading --- composer.json | 4 +- src/EazyJsonRpc/BaseJsonRpcCall.php | 85 +++++++++++++++++++ src/{ => EazyJsonRpc}/BaseJsonRpcClient.php | 80 +---------------- src/{ => EazyJsonRpc}/BaseJsonRpcServer.php | 0 .../BaseJsonRpcServerSmd.php | 0 tests/bootstrap.php | 6 +- tests/example-server.php | 4 +- 7 files changed, 94 insertions(+), 85 deletions(-) create mode 100644 src/EazyJsonRpc/BaseJsonRpcCall.php rename src/{ => EazyJsonRpc}/BaseJsonRpcClient.php (71%) rename src/{ => EazyJsonRpc}/BaseJsonRpcServer.php (100%) rename src/{ => EazyJsonRpc}/BaseJsonRpcServerSmd.php (100%) diff --git a/composer.json b/composer.json index e2a6b01..8ba9dea 100644 --- a/composer.json +++ b/composer.json @@ -29,7 +29,9 @@ }, "target-dir":"", "require":{ - "php":">=5.4.0" + "php":">=5.4.0", + "ext-curl": "*", + "ext-json": "*" }, "require-dev":{ "phpunit/phpunit": "4.8.*" diff --git a/src/EazyJsonRpc/BaseJsonRpcCall.php b/src/EazyJsonRpc/BaseJsonRpcCall.php new file mode 100644 index 0000000..e81d6eb --- /dev/null +++ b/src/EazyJsonRpc/BaseJsonRpcCall.php @@ -0,0 +1,85 @@ +Error; + } + + + /** + * @param string $method + * @param array $params + * @param string $id + */ + public function __construct($method, $params, $id) + { + $this->Method = $method; + $this->Params = $params; + $this->Id = $id; + } + + + /** + * Get Call Data + * @param BaseJsonRpcCall $call + * @return array + */ + public static function GetCallData(BaseJsonRpcCall $call) + { + return [ + 'jsonrpc' => '2.0', + 'id' => $call->Id, + 'method' => $call->Method, + 'params' => $call->Params, + ]; + } + + + /** + * Set Result + * @param mixed $data + * @param bool $useObjects + */ + public function SetResult($data, $useObjects = false) + { + if ($useObjects) { + $this->Error = property_exists($data, 'error') ? $data->error : null; + $this->Result = property_exists($data, 'result') ? $data->result : null; + } else { + $this->Error = !empty($data['error']) ? $data['error'] : null; + $this->Result = !empty($data['result']) ? $data['result'] : null; + } + } +} \ No newline at end of file diff --git a/src/BaseJsonRpcClient.php b/src/EazyJsonRpc/BaseJsonRpcClient.php similarity index 71% rename from src/BaseJsonRpcClient.php rename to src/EazyJsonRpc/BaseJsonRpcClient.php index f145282..75381d0 100644 --- a/src/BaseJsonRpcClient.php +++ b/src/EazyJsonRpc/BaseJsonRpcClient.php @@ -159,7 +159,7 @@ public function __call( $method, array $parameters = [ ] ) { protected function processCalls( $calls ) { // Prepare Data $singleCall = !$this->isBatchCall ? reset( $calls ) : null; - $result = $this->batchCalls ? array_values( array_map( '\EazyJsonRpc\BaseJsonRpcCall::GetCallData', $calls ) ) : BaseJsonRpcCall::GetCallData( $singleCall ); + $result = $this->batchCalls ? array_values( array_map( '\EazyJsonRpc\BaseJsonRpcCall', $calls ) ) : BaseJsonRpcCall::GetCallData( $singleCall ); // Send Curl Request $options = $this->CurlOptions + [ CURLOPT_POSTFIELDS => json_encode( $result ) ]; @@ -189,81 +189,3 @@ protected function processCalls( $calls ) { } } - - /** - * Base Json Rpc Call - * @package Eaze - * @subpackage Model - * @author Sergeyfast - * @link http://www.jsonrpc.org/specification - */ - class BaseJsonRpcCall { - - /** @var int */ - public $Id; - - /** @var string */ - public $Method; - - /** @var array */ - public $Params; - - /** @var array */ - public $Error; - - /** @var mixed */ - public $Result; - - - /** - * Has Error - * @return bool - */ - public function HasError() { - return (bool) $this->Error; - } - - - /** - * @param string $method - * @param array $params - * @param string $id - */ - public function __construct( $method, $params, $id ) { - $this->Method = $method; - $this->Params = $params; - $this->Id = $id; - } - - - /** - * Get Call Data - * @param BaseJsonRpcCall $call - * @return array - */ - public static function GetCallData( BaseJsonRpcCall $call ) { - return [ - 'jsonrpc' => '2.0', - 'id' => $call->Id, - 'method' => $call->Method, - 'params' => $call->Params, - ]; - } - - - /** - * Set Result - * @param mixed $data - * @param bool $useObjects - */ - public function SetResult( $data, $useObjects = false ) { - if ( $useObjects ) { - $this->Error = property_exists( $data, 'error' ) ? $data->error : null; - $this->Result = property_exists( $data, 'result' ) ? $data->result : null; - } else { - $this->Error = !empty( $data['error'] ) ? $data['error'] : null; - $this->Result = !empty( $data['result'] ) ? $data['result'] : null; - } - } - } - diff --git a/src/BaseJsonRpcServer.php b/src/EazyJsonRpc/BaseJsonRpcServer.php similarity index 100% rename from src/BaseJsonRpcServer.php rename to src/EazyJsonRpc/BaseJsonRpcServer.php diff --git a/src/BaseJsonRpcServerSmd.php b/src/EazyJsonRpc/BaseJsonRpcServerSmd.php similarity index 100% rename from src/BaseJsonRpcServerSmd.php rename to src/EazyJsonRpc/BaseJsonRpcServerSmd.php diff --git a/tests/bootstrap.php b/tests/bootstrap.php index 16568b1..6e8fc6c 100644 --- a/tests/bootstrap.php +++ b/tests/bootstrap.php @@ -1,7 +1,7 @@