##Build Status
The current version is considered Beta. This means that it is ready enough to test and use, but beware that you should update frequently.
As this software is BETA, Use at your own risk!
JSON-RPC Server/Client for PHP 5.3
Download the latest phar build. Then, just require the phar in your code!
require_once '/path/to/JsonRpcLib.phar';
Add a composer.json
file to your project with the following:
{
"require": {
"json-rpc-lib/json-rpc-lib": "dev-master"
}
}
Then, inside that folder, just run php composer.phar install
.
Then, in your code, just use the composer autoloader:
require_once 'vendor/autoload.php';
That's it!
Most use-cases can simply use the root JsonRpcLib\Server\Server
class.
<?php
require_once 'vendor/autoload.php';
$server = new \JsonRpcLib\Server\Server();
$server->addService($service);
$server->handle();
<?php
require_once 'vendor/autoload.php';
$server = new \JsonRpcLib\Server\Server();
$server->addService(function($a, $b) {
return $a + $b;
}, 'sum'); // sum
$server->handle();
<?php
require_once 'vendor/autoload.php';
class MockService {
public function sum($a, $b) {
return $a + $b;
}
}
$service = new MockService();
$server = new \JsonRpcLib\Server\Server();
$server->addService($service); // sum
$server->handle();
or
<?php
// ...
$server->addService($service, 'math'); // math.sum
// ...
<?php
// ...
$server->addService($service, 'math'); // math.sum
$server->addService(function($data){
// update data
}, 'update'); // update
$server->addService(function($a, $b){
return $a + $b;
}, 'sum'); // sum
$server->addService($userService, 'user'); // user.getName, user.getSurname, user.*
// ...
<?php
$in = new JsonRpcLib\Server\Input\Data\Input();
$out = new JsonRpcLib\Server\Output\Data\Output();
$inputMessage = new JsonRpcLib\Server\Input\Message($in);
$outputMessage = new JsonRpcLib\Server\Output\Message($out);
$resolver = new \JsonRpcLib\Server\Service\Resolver\Resolver();
$manager = new JsonRpcLib\Server\Service\Manager\Manager($resolver);
$server = new JsonRpcLib\Server\Server($manager);
$server->addService(new \JsonRpcLib\Server\Service\Wrapper\ClosureWrapper($closure), 'getYear');
$server->addService(new \JsonRpcLib\Server\Service\Wrapper\ObjectWrapper($object), 'getName');
$server->dispatch($inputMessage, $outputMessage);
The code will use industry standard design patterns as well as follow guidelines for clean and testable code.
That means that the code should be well covered by unit tests.
PHP JsonRpcLib will support two install methods. The first method is a single file PHAR archive. The second is support via Composer.
The library should be very easy to extend and add new functionality.