2017-25 © Pedro Peláez
 

library jsonrpc-params-symfony-validator-sdk

Simple JSON-RPC params validator that use Symfony validator component

image

yoanm/jsonrpc-params-symfony-validator-sdk

Simple JSON-RPC params validator that use Symfony validator component

  • Saturday, June 2, 2018
  • by yoanm
  • Repository
  • 0 Watchers
  • 0 Stars
  • 26 Installations
  • Makefile
  • 1 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 6 Versions
  • 0 % Grown

The README.md

JSON-RPC params symfony validator

License Code size Dependabot Status, (*1)

Scrutinizer Build Status Scrutinizer Code Quality Codacy Badge, (*2)

CI codecov Symfony Versions, (*3)

Latest Stable Version Packagist PHP version, (*4)

Simple JSON-RPC params validator that use Symfony validator component, (*5)

See yoanm/symfony-jsonrpc-params-validator for automatic dependency injection., (*6)

See yoanm/jsonrpc-params-symfony-constraint-doc-sdk for documentation generation., (*7)

Versions

  • Symfony v3/4 - PHP >=7.1 : ^v1.0
  • Symfony v4/5 - PHP >=7.2 : ^v2.0, (*8)

    ⚠️⚠️ v0.2.0 is replaced by v1.0.0 ! ⚠️⚠️, (*9)

    ⚠️⚠️ v0.3.0 was badly taggued, used v2.0.0 instead ! ⚠️⚠️, (*10)

  • Symfony v4.4/5.4/6.0 - PHP ^8.0 : ^v2.1, (*11)

How to use

In order to be validated, a JSON-RPC method must : * Implements JsonRpcMethodInterface from yoanm/jsonrpc-server-sdk * Implements MethodWithValidatedParamsInterface, (*12)

With yoanm/jsonrpc-server-sdk

Create the validator and inject it into request handler :, (*13)

$requestHandler->setMethodParamsValidator(
  new JsonRpcParamsValidator(
    (new ValidatorBuilder())->getValidator()
  )
);

Then you can send JSON-RPC request string to the server and any method wich implements MethodWithValidatedParamsInterface will be validated., (*14)

Standalone

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

Params validation example

use Symfony\Component\Validator\Constraint;
use Symfony\Component\Validator\Constraints\Collection;
use Symfony\Component\Validator\Constraints\NotBlank;
use Symfony\Component\Validator\Constraints\NotNull;
use Yoanm\JsonRpcParamsSymfonyValidator\Domain\MethodWithValidatedParamsInterface;
use Yoanm\JsonRpcServer\Domain\JsonRpcMethodInterface;

class MethodExample implements JsonRpcMethodInterface, MethodWithValidatedParamsInterface
{
  /**
   * {@inheritdoc}
   */
  public function apply(array $paramList = null)
  {
    return 'result';
  }

  public function getParamsConstraint(): Constraint
  {
    return new Collection(
      [
        'fields' => [
          'fieldA' => new NotNull(),
          'fieldB' => new NotBlank(),
        ],
      ]
    );
  }
}

Violations format

Each violations will have the following format :, (*15)

[
  'path' => 'property_path',
  'message' => 'violation message',
  'code' => 'violation_code'
]

Contributing

See contributing note, (*16)

The Versions

02/06 2018

dev-release/1.0.0

dev-release/1.0.0

Simple JSON-RPC params validator that use Symfony validator component

  Sources   Download

MIT

The Requires

 

The Development Requires

by Avatar yoanm

20/05 2018

dev-release/1.0.0-validator

dev-release/1.0.0-validator

Simple JSON-RPC params validator that use Symfony validator component

  Sources   Download

MIT

The Requires

 

The Development Requires

by Avatar yoanm