2017 © Pedro Peláez
 

library json-rpc-validator

Auth extension for JSON-RPC library

image

datto/json-rpc-validator

Auth extension for JSON-RPC library

  • Tuesday, December 19, 2017
  • by binwiederhier
  • Repository
  • 5 Watchers
  • 3 Stars
  • 6,253 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 2 Forks
  • 0 Open issues
  • 3 Versions
  • 2 % Grown

The README.md

JSON-RPC Endpoint Validator Extension

This is an annotation-based validation extension for the php-json-rpc library. It validates the JSON-RPC API endpoints against well-defined constraints, e.g. type checking, regex checking, etc., (*1)

The library depends on symfony/Validator, doctrine/annotations as well as on php-json-rpc-simple., (*2)

Examples

Annotate your API endpoint classes like this:, (*3)

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;
    }

Once you have that, just use it like this. This example uses the Simple\Evaluator (see php-json-rpc-simple) as underlying mapping mechanism:, (*4)

$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"}}

Requirements

  • PHP >= 5.3

Installation

"require": {
  "datto/json-rpc-validator": "~2.0"
}

License

This package is released under an open-source license: LGPL-3.0., (*5)

Author

Written by Philipp C. Heckel., (*6)

The Versions

19/12 2017

dev-master

9999999-dev http://www.datto.com

Auth extension for JSON-RPC library

  Sources   Download

LGPL-3.0

The Requires

 

The Development Requires

by Philipp Heckel

19/12 2017

5.0.0

5.0.0.0 http://www.datto.com

Auth extension for JSON-RPC library

  Sources   Download

LGPL-3.0

The Requires

 

The Development Requires

by Philipp Heckel

15/12 2015

4.0.0

4.0.0.0 http://www.datto.com

Auth extension for JSON-RPC library

  Sources   Download

LGPL-3.0

The Requires

 

by Philipp Heckel