Skip to content

Commit cc57da6

Browse files
committed
Version 3.5.2
2 parents d943875 + b5653b5 commit cc57da6

File tree

14 files changed

+119
-44
lines changed

14 files changed

+119
-44
lines changed

.gitignore

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,8 @@
22
.session
33
.buildpath
44
.project
5-
.settings/org.eclipse.php.core.prefs
5+
.settings/org.eclipse.php.core.prefs
6+
7+
# Composer
8+
/vendor
9+
/composer.lock

lib/Tivoka/Client.php

Lines changed: 25 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ abstract class Client
4141
/**
4242
* Initializes a Connection to a remote server
4343
* @param mixed $target Remote end-point definition
44-
* @return Tivoka\Client\Connection\ConnectionInterface
44+
* @return Client\Connection\ConnectionInterface
4545
*/
4646
public static function connect($target) {
4747
return Client\Connection\AbstractConnection::factory($target);
@@ -51,30 +51,40 @@ public static function connect($target) {
5151
* Creates a request
5252
* @param string $method The method to invoke
5353
* @param array $params The parameters
54-
* @return Tivoka\Client\Request
54+
* @return Client\Request
5555
*/
5656
public static function createRequest($method, $params=null) {
5757
return new Client\Request($method, $params);
5858
}
5959

6060
/**
6161
* alias of Tivoka\Client::createRequest
62+
* @see Client::createRequest
6263
*/
6364
public static function request($method, $params=null) {
6465
return self::createRequest($method, $params);
6566
}
66-
67+
6768
/**
6869
* Creates a notification
70+
*
6971
* @param string $method The method to invoke
7072
* @param array $params The parameters
73+
*
74+
* @return Client\Notification
7175
*/
7276
public static function createNotification($method, $params=null) {
7377
return new Client\Notification($method, $params);
7478
}
75-
79+
7680
/**
7781
* alias of Tivoka\Client::createNotification
82+
* @see Client::createNotification
83+
84+
* @param string $method The method to invoke
85+
* @param array $params The parameters
86+
*
87+
* @return Client\Notification
7888
*/
7989
public static function notification($method, $params=null) {
8090
return self::createNotification($method, $params);
@@ -83,21 +93,28 @@ public static function notification($method, $params=null) {
8393
/**
8494
* Creates a batch request
8595
* @param mixed $request either an array of requests or a comma-seperated list of requests
86-
* @throws Tivoka\Exception\Exception
87-
* @return Tivoka\Client\BatchRequest
96+
*
97+
* @return Client\BatchRequest
98+
* @throws Exception\Exception
8899
*/
89100
public static function createBatch($request) {
90101
if(func_num_args() > 1 ) $request = func_get_args();
91102
if(!is_array($request)) throw new Exception\Exception('Object of invalid data type passed to Tivoka::createBatch.');
92103
return new Client\BatchRequest($request);
93104
}
94-
105+
95106
/**
96107
* alias of Tivoka\Client::createBatch
108+
* @see Client::createBatch
109+
*
110+
* @param mixed $request either an array of requests or a comma-seperated list of requests
111+
*
112+
* @return Client\BatchRequest
113+
* @throws Exception\Exception
97114
*/
98115
public static function batch($request) {
99116
if(func_num_args() > 1 ) $request = func_get_args();
100117
return self::createBatch($request);
101118
}
102119
}
103-
?>
120+
?>

lib/Tivoka/Client/BatchRequest.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,8 +68,11 @@ public function __construct(array $batch)
6868

6969
/**
7070
* Get the raw, JSON-encoded request
71+
*
7172
* @param int $spec
73+
*
7274
* @return string the JSON encoded request
75+
* @throws Exception\SpecException
7376
*/
7477
public function getRequest($spec) {
7578
if($spec == Tivoka::SPEC_1_0) throw new Exception\SpecException('Batch requests are not supported by JSON-RPC 1.0 spec');
@@ -83,8 +86,11 @@ public function getRequest($spec) {
8386

8487
/**
8588
* Interprets the parsed response
89+
*
8690
* @param array $json_struct json data
91+
*
8792
* @return void
93+
* @throws Exception\SyntaxException
8894
*/
8995
public function interpretResponse($json_struct) {
9096
//validate

lib/Tivoka/Client/Connection/AbstractConnection.php

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,10 @@ abstract class AbstractConnection implements ConnectionInterface {
6464

6565
/**
6666
* Sets the spec version to use for this connection
67+
*
6768
* @param string $spec The spec version (e.g.: "2.0")
69+
*
70+
* @return $this
6871
*/
6972
public function useSpec($spec) {
7073
$this->spec = Tivoka::validateSpecVersion($spec);
@@ -74,7 +77,7 @@ public function useSpec($spec) {
7477
/**
7578
* Changes connection options.
7679
* @param array $options
77-
* @return Self reference.
80+
* @return $this Self reference.
7881
*/
7982
public function setOptions($options) {
8083
$this->options = $options;
@@ -84,7 +87,7 @@ public function setOptions($options) {
8487
/**
8588
* Changes timeout.
8689
* @param int $timeout
87-
* @return Self reference.
90+
* @return $this Self reference.
8891
*/
8992
public function setTimeout($timeout)
9093
{
@@ -95,8 +98,11 @@ public function setTimeout($timeout)
9598

9699
/**
97100
* Send a request directly
101+
*
98102
* @param string $method
99103
* @param array $params
104+
*
105+
* @return Request
100106
*/
101107
public function sendRequest($method, $params=null) {
102108
$request = new Request($method, $params);
@@ -115,7 +121,7 @@ public function sendNotification($method, $params=null) {
115121

116122
/**
117123
* Creates a native remote interface for the target server
118-
* @return Tivoka\Client\NativeInterface
124+
* @return NativeInterface
119125
*/
120126
public function getNativeInterface()
121127
{

lib/Tivoka/Client/Connection/ConnectionInterface.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
namespace Tivoka\Client\Connection;
3333

3434
use Tivoka\Client\Request;
35+
use Tivoka\Client\NativeInterface;
3536

3637
/**
3738
* Connection interface
@@ -73,7 +74,7 @@ public function sendNotification($method, $params=null);
7374

7475
/**
7576
* Creates a native remote interface for the target server
76-
* @return Tivoka\Client\NativeInterface
77+
* @return NativeInterface
7778
*/
7879
public function getNativeInterface();
7980
}

lib/Tivoka/Client/Connection/Http.php

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,8 @@ class Http extends AbstractConnection {
4949
* Constructs connection
5050
* @access private
5151
* @param string $target URL
52+
*
53+
* @throws Exception\Exception
5254
*/
5355
public function __construct($target) {
5456
//validate url...
@@ -83,8 +85,8 @@ public function __destruct() {
8385

8486
/**
8587
* Sets the HTTP headers to use for upcoming send requests
86-
* @param string label of header
87-
* @param string value of header
88+
* @param string $label label of header
89+
* @param string $value value of header
8890
* @return Http Self instance
8991
*/
9092
public function setHeader($label, $value) {
@@ -94,8 +96,11 @@ public function setHeader($label, $value) {
9496

9597
/**
9698
* Sends a JSON-RPC request
99+
*
97100
* @param Request $request A Tivoka request
101+
*
98102
* @return Request if sent as a batch request the BatchRequest object will be returned
103+
* @throws Exception\Exception
99104
*/
100105
public function send(Request $request) {
101106
if(func_num_args() > 1 ) $request = func_get_args();

lib/Tivoka/Client/Connection/Tcp.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,8 @@ class Tcp extends AbstractConnection {
6363
* Constructs connection.
6464
* @param string $host Server host.
6565
* @param int $port Server port.
66+
*
67+
* @throws Exception\Exception
6668
*/
6769
public function __construct($host, $port)
6870
{
@@ -104,8 +106,12 @@ public function setTimeout($timeout)
104106

105107
/**
106108
* Sends a JSON-RPC request over plain TCP.
109+
*
107110
* @param Request $request,... A Tivoka request.
111+
*
108112
* @return Request|BatchRequest If sent as a batch request the BatchRequest object will be returned.
113+
* @throws Exception\ConnectionException
114+
* @throws Exception\Exception
109115
*/
110116
public function send(Request $request)
111117
{

lib/Tivoka/Client/Connection/WebSocket.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,11 @@ public function setTimeout($timeout)
5252

5353
/**
5454
* Sends a JSON-RPC request over plain WebSocket.
55+
*
5556
* @param Request $request,... A Tivoka request.
57+
*
5658
* @return Request|BatchRequest If sent as a batch request the BatchRequest object will be returned.
59+
* @throws Exception\Exception
5760
*/
5861
public function send(Request $request)
5962
{
@@ -80,7 +83,7 @@ public function send(Request $request)
8083
}
8184

8285
/**
83-
* @return The websocket URI used.
86+
* @return string The websocket URI used.
8487
*/
8588
public function getUri()
8689
{

lib/Tivoka/Client/NativeInterface.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ class NativeInterface {
4141

4242
/**
4343
* Holds the last request
44-
* @var Tivoka\Client\Request
44+
* @var Request
4545
*/
4646
public $last_request;
4747

@@ -61,7 +61,7 @@ public function __construct(ConnectionInterface $connection) {
6161

6262
/**
6363
* Sends a JSON-RPC request
64-
* @throws Tivoka\Exception\RemoteProcedureException
64+
* @throws Exception\RemoteProcedureException
6565
* @return mixed
6666
*/
6767
public function __call($method, $args) {
@@ -75,4 +75,4 @@ public function __call($method, $args) {
7575
}
7676

7777
}
78-
?>
78+
?>

lib/Tivoka/Client/Request.php

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -103,8 +103,12 @@ protected static function http_parse_headers($headers) {
103103

104104
/**
105105
* Interprets the response
106+
*
106107
* @param string $response json data
108+
*
107109
* @return void
110+
* @throws Exception\ConnectionException
111+
* @throws Exception\SyntaxException
108112
*/
109113
public function setResponse($response) {
110114
$this->response = $response;
@@ -135,7 +139,10 @@ public function setHeaders($raw_headers) {
135139

136140
/**
137141
* Interprets the parsed response
142+
*
138143
* @param array $json_struct
144+
*
145+
* @throws Exception\SyntaxException
139146
*/
140147
public function interpretResponse($json_struct) {
141148
//server error?
@@ -215,17 +222,24 @@ protected static function interpretError($spec, array $assoc, $id)
215222
if(isset($assoc['error']) === FALSE) return FALSE;
216223
return array(
217224
'id' => $assoc['id'],
218-
'error' => array('data' => $assoc['error'])
225+
'error' => array(
226+
'data' => $assoc['error'],
227+
'code' => $assoc['error'],
228+
'message' => $assoc['error']
229+
)
219230
);
220231
}
221232
}
222233

223234
/**
224235
* Encodes the request properties
236+
*
225237
* @param mixed $id The id of the request
226238
* @param string $method The method to be called
227239
* @param array $params Additional parameters
240+
*
228241
* @return mixed the prepared assotiative array to encode
242+
* @throws Exception\SpecException
229243
*/
230244
protected static function prepareRequest($spec, $id, $method, $params=null) {
231245
switch($spec) {
@@ -253,7 +267,7 @@ protected static function prepareRequest($spec, $id, $method, $params=null) {
253267
/**
254268
* @return string A v4 uuid
255269
*/
256-
static function uuid()
270+
public static function uuid()
257271
{
258272
return sprintf('%04x%04x-%04x-%04x-%04x-%04x%04x%04x',
259273
mt_rand(0, 0xffff), mt_rand(0, 0xffff), // time_low
@@ -264,4 +278,4 @@ static function uuid()
264278
);
265279
}
266280
}
267-
?>
281+
?>

0 commit comments

Comments
 (0)