Skip to content

Commit

Permalink
Fix classes autoloading
Browse files Browse the repository at this point in the history
  • Loading branch information
sas1024 committed Apr 5, 2021
1 parent 8480b59 commit 8d1512a
Show file tree
Hide file tree
Showing 7 changed files with 94 additions and 85 deletions.
4 changes: 3 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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.*"
Expand Down
85 changes: 85 additions & 0 deletions src/EazyJsonRpc/BaseJsonRpcCall.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
<?php

namespace EazyJsonRpc;

/**
* 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;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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 ) ];
Expand Down Expand Up @@ -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;
}
}
}

File renamed without changes.
File renamed without changes.
6 changes: 3 additions & 3 deletions tests/bootstrap.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?php
include '../src/BaseJsonRpcServer.php';
include '../src/BaseJsonRpcServerSmd.php';
include '../src/BaseJsonRpcClient.php';
include '../src/EazyJsonRpc/BaseJsonRpcServer.php';
include '../src/EazyJsonRpc/BaseJsonRpcServerSmd.php';
include '../src/EazyJsonRpc/BaseJsonRpcClient.php';
include 'lib/DateTimeService.php';
include 'lib/DateTimeServiceClient.php';
include 'lib/DatePingServiceClient.php';
Expand Down
4 changes: 2 additions & 2 deletions tests/example-server.php
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<?php
use EazyJsonRpc\BaseJsonRpcServer;

include '../src/BaseJsonRpcServer.php';
include '../src/BaseJsonRpcServerSmd.php';
include '../src/EazyJsonRpc/BaseJsonRpcServer.php';
include '../src/EazyJsonRpc/BaseJsonRpcServerSmd.php';
include 'lib/DateTimeService.php';
include 'lib/PingService.php';
include 'lib/DateTimeRpcService.php';
Expand Down

0 comments on commit 8d1512a

Please sign in to comment.