1. Go to this page and download the library: Download datto/json-rpc-validator library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
datto / json-rpc-validator example snippets
namespace Datto\API;
use Datto\JsonRpc\Validator\Validate;
use Symfony\Component\Validator\Constraints as Assert;
class Math
{
/**
* @Validate(fields={
* "a" = @Assert\Type(type="integer"),
* "b" = {
* @Assert\Type(type="integer"),
* @Assert\NotEqualTo(value="0"),
* }
* })
*/
public function divide($a, $b)
{
return $a / $b;
}
$server = new Server(new Validator\Evaluator(new Simple\Evaluator()));
$result = $server->reply('{"jsonrpc": "2.0", "method": "math/divide", "params": { "a": 1, "b": 0 }, "id": 1}');
// Because 'b' cannot be 0, this will return
// {"jsonrpc":"2.0","id":1,"error":{"code":-32602,"message":"Invalid params"}}
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.