My favorites | Sign in
Project Home Wiki Issues Source
READ-ONLY: This project has been archived. For more information see this post.
Search
for
  Advanced search   Search tips   Subscriptions

Issue 1 attachment: Client.patch (1.9 KB)

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
Index: Client.php
===================================================================
--- Client.php (revision 2)
+++ Client.php (working copy)
@@ -44,8 +44,15 @@
* @var string
*/
protected $_url;
-
+
/**
+ * json decode returns an associative array
+ *
+ * @var boolean
+ */
+ protected $_assoc = false;
+
+ /**
* Notification mode
*
* @var boolean
@@ -56,9 +63,11 @@
* Constructor
*
* @param string $url
+ * @param boolean $assoc
*/
- public function __construct($url) {
+ public function __construct($url, $assoc = false) {
$this->_url = $url;
+ $this->_assoc = $assoc;
}

/**
@@ -98,19 +107,30 @@
throw new Exception('Unable to connect to ' . $this->_url);
}

- $response = json_decode($response);
+ $response = json_decode($response, $this->_assoc);
if ($response === null) {
throw new Exception('Malformed response');
}
-
- if ($response->id != $request['id']) {
- throw new Exception('Incorrect response id. Expected:' . $request['id'] . ' Received:' . $response->id);
+ if($this->_assoc) {
+ if ($response['id'] != $request['id']) {
+ throw new Exception('Incorrect response id. Expected:' . $request['id'] . ' Received:' . $response['id']);
+ }
+
+ if (!is_null($response['error'])) {
+ throw new Exception('JSON-RPC Request Error: ' . $response['error']);
+ }
+
+ return $this->_notification ? true : $response['result'];
+ } else {
+ if ($response->id != $request['id']) {
+ throw new Exception('Incorrect response id. Expected:' . $request['id'] . ' Received:' . $response->id);
+ }
+
+ if (!is_null($response->error)) {
+ throw new Exception('JSON-RPC Request Error: ' . $response->error);
+ }
+
+ return $this->_notification ? true : $response->result;
}
-
- if (!is_null($response->error)) {
- throw new Exception('JSON-RPC Request Error: ' . $response->error);
- }
-
- return $this->_notification ? true : $response->result;
}
}
Powered by Google Project Hosting