Skip to content

Commit 8d1512a

Browse files
committed
Fix classes autoloading
1 parent 8480b59 commit 8d1512a

File tree

7 files changed

+94
-85
lines changed

7 files changed

+94
-85
lines changed

composer.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,9 @@
2929
},
3030
"target-dir":"",
3131
"require":{
32-
"php":">=5.4.0"
32+
"php":">=5.4.0",
33+
"ext-curl": "*",
34+
"ext-json": "*"
3335
},
3436
"require-dev":{
3537
"phpunit/phpunit": "4.8.*"
Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
<?php
2+
3+
namespace EazyJsonRpc;
4+
5+
/**
6+
* Base Json Rpc Call
7+
* @package Eaze
8+
* @subpackage Model
9+
* @author Sergeyfast
10+
* @link http://www.jsonrpc.org/specification
11+
*/
12+
class BaseJsonRpcCall
13+
{
14+
15+
/** @var int */
16+
public $Id;
17+
18+
/** @var string */
19+
public $Method;
20+
21+
/** @var array */
22+
public $Params;
23+
24+
/** @var array */
25+
public $Error;
26+
27+
/** @var mixed */
28+
public $Result;
29+
30+
31+
/**
32+
* Has Error
33+
* @return bool
34+
*/
35+
public function HasError()
36+
{
37+
return (bool)$this->Error;
38+
}
39+
40+
41+
/**
42+
* @param string $method
43+
* @param array $params
44+
* @param string $id
45+
*/
46+
public function __construct($method, $params, $id)
47+
{
48+
$this->Method = $method;
49+
$this->Params = $params;
50+
$this->Id = $id;
51+
}
52+
53+
54+
/**
55+
* Get Call Data
56+
* @param BaseJsonRpcCall $call
57+
* @return array
58+
*/
59+
public static function GetCallData(BaseJsonRpcCall $call)
60+
{
61+
return [
62+
'jsonrpc' => '2.0',
63+
'id' => $call->Id,
64+
'method' => $call->Method,
65+
'params' => $call->Params,
66+
];
67+
}
68+
69+
70+
/**
71+
* Set Result
72+
* @param mixed $data
73+
* @param bool $useObjects
74+
*/
75+
public function SetResult($data, $useObjects = false)
76+
{
77+
if ($useObjects) {
78+
$this->Error = property_exists($data, 'error') ? $data->error : null;
79+
$this->Result = property_exists($data, 'result') ? $data->result : null;
80+
} else {
81+
$this->Error = !empty($data['error']) ? $data['error'] : null;
82+
$this->Result = !empty($data['result']) ? $data['result'] : null;
83+
}
84+
}
85+
}
Lines changed: 1 addition & 79 deletions
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ public function __call( $method, array $parameters = [ ] ) {
159159
protected function processCalls( $calls ) {
160160
// Prepare Data
161161
$singleCall = !$this->isBatchCall ? reset( $calls ) : null;
162-
$result = $this->batchCalls ? array_values( array_map( '\EazyJsonRpc\BaseJsonRpcCall::GetCallData', $calls ) ) : BaseJsonRpcCall::GetCallData( $singleCall );
162+
$result = $this->batchCalls ? array_values( array_map( '\EazyJsonRpc\BaseJsonRpcCall', $calls ) ) : BaseJsonRpcCall::GetCallData( $singleCall );
163163

164164
// Send Curl Request
165165
$options = $this->CurlOptions + [ CURLOPT_POSTFIELDS => json_encode( $result ) ];
@@ -189,81 +189,3 @@ protected function processCalls( $calls ) {
189189
}
190190
}
191191

192-
193-
/**
194-
* Base Json Rpc Call
195-
* @package Eaze
196-
* @subpackage Model
197-
* @author Sergeyfast
198-
* @link http://www.jsonrpc.org/specification
199-
*/
200-
class BaseJsonRpcCall {
201-
202-
/** @var int */
203-
public $Id;
204-
205-
/** @var string */
206-
public $Method;
207-
208-
/** @var array */
209-
public $Params;
210-
211-
/** @var array */
212-
public $Error;
213-
214-
/** @var mixed */
215-
public $Result;
216-
217-
218-
/**
219-
* Has Error
220-
* @return bool
221-
*/
222-
public function HasError() {
223-
return (bool) $this->Error;
224-
}
225-
226-
227-
/**
228-
* @param string $method
229-
* @param array $params
230-
* @param string $id
231-
*/
232-
public function __construct( $method, $params, $id ) {
233-
$this->Method = $method;
234-
$this->Params = $params;
235-
$this->Id = $id;
236-
}
237-
238-
239-
/**
240-
* Get Call Data
241-
* @param BaseJsonRpcCall $call
242-
* @return array
243-
*/
244-
public static function GetCallData( BaseJsonRpcCall $call ) {
245-
return [
246-
'jsonrpc' => '2.0',
247-
'id' => $call->Id,
248-
'method' => $call->Method,
249-
'params' => $call->Params,
250-
];
251-
}
252-
253-
254-
/**
255-
* Set Result
256-
* @param mixed $data
257-
* @param bool $useObjects
258-
*/
259-
public function SetResult( $data, $useObjects = false ) {
260-
if ( $useObjects ) {
261-
$this->Error = property_exists( $data, 'error' ) ? $data->error : null;
262-
$this->Result = property_exists( $data, 'result' ) ? $data->result : null;
263-
} else {
264-
$this->Error = !empty( $data['error'] ) ? $data['error'] : null;
265-
$this->Result = !empty( $data['result'] ) ? $data['result'] : null;
266-
}
267-
}
268-
}
269-

tests/bootstrap.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<?php
2-
include '../src/BaseJsonRpcServer.php';
3-
include '../src/BaseJsonRpcServerSmd.php';
4-
include '../src/BaseJsonRpcClient.php';
2+
include '../src/EazyJsonRpc/BaseJsonRpcServer.php';
3+
include '../src/EazyJsonRpc/BaseJsonRpcServerSmd.php';
4+
include '../src/EazyJsonRpc/BaseJsonRpcClient.php';
55
include 'lib/DateTimeService.php';
66
include 'lib/DateTimeServiceClient.php';
77
include 'lib/DatePingServiceClient.php';

tests/example-server.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
<?php
22
use EazyJsonRpc\BaseJsonRpcServer;
33

4-
include '../src/BaseJsonRpcServer.php';
5-
include '../src/BaseJsonRpcServerSmd.php';
4+
include '../src/EazyJsonRpc/BaseJsonRpcServer.php';
5+
include '../src/EazyJsonRpc/BaseJsonRpcServerSmd.php';
66
include 'lib/DateTimeService.php';
77
include 'lib/PingService.php';
88
include 'lib/DateTimeRpcService.php';

0 commit comments

Comments
 (0)