PHP code example of yoanm / jsonrpc-params-symfony-validator-sdk

1. Go to this page and download the library: Download yoanm/jsonrpc-params-symfony-validator-sdk 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/ */

    

yoanm / jsonrpc-params-symfony-validator-sdk example snippets


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

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

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(),
        ],
      ]
    );
  }
}

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