Generic JSON-RPC v2 implementation
Latest commit 5d6297a Mar 15, 2016 @foglcz Merge pull request #15 from hobrasoft-cz/master
Bugfix: Added compatibility with PHP 5.6
Failed to load latest commit information.
lib Bugfix: Added compatibility with PHP 5.6 Mar 15, 2016
test-suite bugfix Sep 12, 2011
LICENSE.txt Added composer, change in license (removed lightbulb project part) Jul 27, 2012


JSON-RPC version 2 libraries

This library contains a PHP implementation of JSON-RPC version 2. The library consist of both server and client implementations.

Both server and client supports for "dots magic". That is, every method called using the RPC classes can contain dots. The dots then separates individual objects. ie:

$client = new Lightbulb\Json\Rpc2\Client('http://endpoint');

will actually result in following json call:

{... method: "first.second.third" ...}

With server, you just define the variable with a class. Eg. "user.login" and "user.stuff" can be achieved like this:

$server = new Lightbulb\Json\Rpc2\Server;
$server->user = new MyJsonUserHandler;

This is particulary handy in order to separate individual methods within robust APIs. Handlers can be individual methods as well. Feel free to do anything of the following:

$server->myTest = new MyTestHandler; // contains mytest.* methods
$server->myFunction = function($param1, $param2) { /* ... */ };
$server->{'mytesthandler.myfunc'} = array($myObject, 'myMethod');
$server->myStaticHandler = 'MyStaticClass::theStaticFunction';

The methods, which are given to the server, can be then called via numbered or named parameters (see json-rpc specification here: )

Methods can have optional arguments:

$server->user->login = function($email, $password, $permanent = false)

The server class respects binding of event methods:

// Bind events
$server->onBeforeCall[] = function($server) {};
$server->onBeforeCall[] = function($server) {};
$server->onSuccess[] = function($server) {};
$server->onError[] = function($server) {};

// Another way of in-binding the events; it does *not* remove the last one
$server->onError = function($server) {};

For detailed usage see comments with the server and clients class. For detailed tests see tests folder.

There is an example implementation of the presenter within "example" folder, which can be used for Nette Framework (TM)

Test suite

Within "test-suite" folder you can find implementation of the generic test-suite module for Nette Framework projects. With that, you can simply semi-generate the test suite, which you can use both for reference & mainly testing of all your methods.


Download contents of the lib/* folder and put them into your project. If you want to use test-suite or examples, you need to use Nette Framework. That awesome framework can be obtained at

Known bugs

Due to the nature of PHP, when you use optional argument of method like this:

$server->user->store($object = null)

you cannot then use "exact resolution operator" === . Hence, only following is applicable:

if($object != null) // note the "!="

This applies only to NULL variables.


Contact me directly using e-mail at <birdie at animalgroup dot cz> or on twitter @foglcz , or of course, in here.


Licensed under the New BSD License. Copyright 2011 Pavel Ptacek. All rights reserved.