Download the PHP package operation-hardcode/php-rpc-server without Composer
On this page you can find all versions of the php package operation-hardcode/php-rpc-server. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download operation-hardcode/php-rpc-server
More information about operation-hardcode/php-rpc-server
Files in operation-hardcode/php-rpc-server
Package php-rpc-server
Short Description JSON RPC server implementation for PHP.
License MIT
Informations about the package php-rpc-server
JSON RPC Server implementation for PHP.
The json-rpc is a very simple protocol. You can see this by reading the protocol specification.
This library implements json-rpc server specification. It is easy to use and well typed.
Contents
- Installation
- Usage
- Examples
- Testing
- Stat Analysis
- License
Installation
Usage
Since the json-rpc server has only one endpoint, you need a handler that knows how to determine from the name of the method the handler that you will handle the request.
You can write it yourself, if the OperationHardcode\PhpRpcServer\RpcHandler
interface is implemented. Or use the ready-made one that comes with the library, the OperationHardcode\PhpRpcServer\InvokableRpcHandler
.
To start to use the rpc server, instantiate the RpcServer
:
The rpc-server does not fetch the json, it just processes it according to the specification. This gives you the freedom to use the server, because you can pass the json fetched any way you know: via http, web sockets or even via tcp.
As you may have noticed, handlers may not have an RpcResponse object. If so, it is a notification, not a request, so no response to the client will follow. You can simply return this object (because it is null) or null directly.
The rpc-server uses validators to validate json against the specification.
If you want to add your own validators, you must implement the OperationHardcode\PhpRpcServer\Protocol\Validation\ValidateRequest
interface. In the validate
method you will get the raw payload to ensure it satisfy your extended protocol rules.
If your validator fails, the error INVALID_REQUEST
will be returned to the client.
If you are not satisfied with the standard request handler, you can write your own.
Examples
More extensive code examples reside in the examples
directory.
Testing
Stat Analysis
License
The MIT License (MIT). See License File for more information.