Simple JSON-RPC params validator that use Symfony validator component
In order to be validated, a JSON-RPC method must :
- Implements
JsonRpcMethodInterface
fromyoanm/jsonrpc-server-sdk
- Implements
MethodWithValidatedParamsInterface
Then use it as following :
use Symfony\Component\Validator\ValidatorBuilder; use Yoanm\JsonRpcParamsSymfonyValidator\Infra\JsonRpcParamsValidator; // Create the validator $paramsValidator = new JsonRpcParamsValidator( (new ValidatorBuilder())->getValidator() ); // Validate a given JSON-RPC method instance against a JSON-RPC request $violationList = $paramsValidator->validate($jsonRpcRequest, $jsonRpcMethod);
Each violations will have the following format :
[ 'path' => 'property_path', 'message' => 'violation message', 'code' => 'violation_code' ]