foglcz / jsonrpc2
jsonrpc2 implementation for generic use. Test suite for Nette Framework included.
Installs: 60 758
Dependents: 1
Suggesters: 0
Security: 0
Stars: 19
Watchers: 3
Forks: 10
Open Issues: 2
pkg:composer/foglcz/jsonrpc2
Requires
- php: >=5.3.2
This package is not auto-updated.
Last update: 2026-01-03 18:39:22 UTC
README
This library contains a PHP implementation of JSON-RPC version 2. This libraray implements both a client and a server.
Installation
Download the contents of the lib folder to your project. Then simply include
the appropriate library:
include "lib/Server.php"; include "lib/Client.php";
Server example
$server = new Lightbulb\Json\Rpc2\Server; // Add functions to the server object to make them callable remotely // Built in PHP functions or user functions $server->upper = 'strtoupper'; $server->getID = 'findUserID'; // Class based: All public methods in MyClass are exposed as user.method $server->user = new MyClass; // Receive and process any incoming RPC calls $server->handle();
More information in advanced options docs.
Warning: Creation of dynamic property XYZ is deprecated
Newer PHPs warn about creating dynamic properties on classes. If you add class
methods to your server you will need to add #[\AllowDynamicProperties]
before the class definition to work around this error.
Client example
$url = 'http://api.domain.com/endpoint'; $client = new Lightbulb\Json\Rpc2\Client($url); $str = $client->upper("kitten"); $id = $client->getID("Jason Doolis");
Client supports class chaining to call nested methods
$ok = $client->user->mail->login($user, $pass); // Maps to 'user.mail.login'
License
Licensed under the New BSD License. Copyright 2011 Pavel Ptacek. All rights reserved.