-
Notifications
You must be signed in to change notification settings - Fork 6
JSON-RPC Client for PHP
License
GruposInternet/jsonRpcClient-PHP
Folders and files
| Name | Name | Last commit message | Last commit date | |
|---|---|---|---|---|
Repository files navigation
# jsonRPC client for PHP
The jsonRPCclient class contains three public methods: the constructor jsonRPCClient->__construct(), the jsonRPCClient->__call() method, forwarding the requests to the JSON-RPC server, and the jsonRPCClient->setRPCNotification(), to establish if the requests are normal requests or notifications.
## Constructor
jsonRPCClient->__construct()
jsonRPCClient->__construct() — Create a new jsonRPCClient object linking it to a JSON-RPC server
### Description
<pre>
class jsonRPCClient {
__construct (string $url[, boolean $debug])
}
</pre>
Create a new jsonRPCClient object linking it to a JSON-RPC server. The created object contains all JSON-RPC service's methods, each with the same parameters, and the methods return the same service structured values.
If required, setting to TRUE the $debug value, debugging informations are sent to the stdout.
### Parameters
url — The JSON-RPS service's URL.
debug — I TRUE, output on the stdout the dialog between server and client. The default value is FALSE.
### Return
Return a jsonRPCClient object.
### Example
<pre>
require_once 'jsonRPCClient.php';
$myExample = new jsonRPCClient('http://somehostname/path/jsonRPCserver');
</pre>
## Magic Call
jsonRPCClient->__call()
jsonRPCClient->__call() — Load any called method in the corresponding method of the JSON-RPC server, forwarding the given parameters
### Description
<pre>
class jsonRPCClient {
mixed __call (string $method, array $params)
}
</pre>
Wathever be the called method for the jsonRPCClient object, __call() converts it in the JSON-RPC method with the same name. The parameters also are forwarded in a fully transaparent way.
__call() is a magic method, it must NOT be called with its own name. It collect every method called (except the explicitely defined ones), converting them in the JSON-RPC form.
### Parameters
method — The name of the required method.
params — The parameters set packaged as an array.
## Return
Return the structured value given by the called method. If the method is called as a notification, return TRUE.
### Example
<pre>
require_once 'jsonRPCClient.php';
$myExample = new jsonRPCClient('http://somehostname/path/jsonRPCserver');
try {
echo 'Your name is <i>'.$myExample->giveMeSomeData('name').'</i><br />'."\n";
$myExample->changeYourState('I am using this function from the network');
echo 'Your status request has been accepted<br />'."\n";
} catch (Exception $e) {
echo nl2br($e->getMessage()).'<br />'."\n";
}
</pre>
## Note
Keep in mind the example: the __call() method isn't called explicitely. Instead, methods that aren't between the explicitely decalred methods of the class are called. These are the JSON-RPC service's methods.
__call() collect every method request not coresponding to any explicitely declared method of the class and manage it as JSON-RPC requests. The parameters too are given as the JSON-RPC method requires, where __call() will package them in an array.
In this way, the __call() method charges on itself the requests and act as a proxy to the JSON-RPC server.
***
### Credits
Modified by Gian Carlo Salvati <gian@salvati.com.br>
Based on Sergio Vaccaro work - Copyright 2007 Sergio Vaccaro <sergio@inservibile.org> See http://jsonrpcphp.org/ for license, docs, sources and info.
About
JSON-RPC Client for PHP
Resources
License
Stars
Watchers
Forks
Releases
No releases published
Packages 0
No packages published