Download the PHP package mihasicehcek/php_json_rpc_2_server without Composer
On this page you can find all versions of the php package mihasicehcek/php_json_rpc_2_server. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download mihasicehcek/php_json_rpc_2_server
More information about mihasicehcek/php_json_rpc_2_server
Files in mihasicehcek/php_json_rpc_2_server
Package php_json_rpc_2_server
Short Description php realisation of JSON RPC 2 Specification
License MIT
Informations about the package php_json_rpc_2_server
PHP JsonRPC2 Server
Description
It is php implementation of the JSON-RPC 2.0 server
Working principle is very simple
- Create an instance of the class \PhpJsonRpc2\JsonRpcServer
- In method setRequest pass instance or array of \PhpJsonRpc2\Request
- Using method getResponse getting instance or array of instances \PhpJsonRpc2\Response
There is also a \PhpJsonRpc2\ICallStrategy interface that can configure \PhpJsonRpc2\JsonRpcServer for changing strategy of calling procedure. By default \PhpJsonRpc2\JsonRpcServer is configured by strategy \PhpJsonRpc2\ClassMethodCallStrategy, that divide request parameter "method"(for example Calculator.sum) by dot and create "Calculator" instance and call its method "sum".
Installation using composer
Examples
Simple Example
Expamle with pre-conversion json string into object
You can convert json into instance or instances array before passing it into server object. That can be implemented using static method\PhpJsonRpc2\Request::requestFactory($json). But in this case you need to look after handling \PhpJsonRpc2\ParseErrorException, that can be throwed in case of invalid json parsing
Notification
Notification if passed, the response is returned null.
Batch
See Batch
Custom strategy call
You can define your own methods strategy call For example we want to provide "method" not as class.method, but invoke some simple functions
Exceptions
All exceptions is subtype of base \PhpJsonRpc2\BaseJsonRpcException. Exceptions not throwing, but its instance returned in response.
If you want to throw an exception in procedures, you need to throw instance of \PhpJsonRpc2\InternalException or its subtype