Skip to content

Commit 082827b

Browse files
authored
Update documentation
1 parent a1da27e commit 082827b

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed

README.md

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,32 @@ Simple JSON-RPC params validator that use Symfony validator component
1111

1212
## How to use
1313

14+
In order to be validated, a JSON-RPC method must :
15+
- Implements `JsonRpcMethodInterface` from [`yoanm/jsonrpc-server-sdk`](https://github.com/yoanm/php-jsonrpc-server-sdk)
16+
- Implements [`MethodWithValidatedParamsInterface`](./src/Infra/JsonRpcParamsValidator.php)
17+
18+
Then use it as following :
19+
```php
20+
use Symfony\Component\Validator\ValidatorBuilder;
21+
use Yoanm\JsonRpcParamsSymfonyValidator\Infra\JsonRpcParamsValidator;
22+
23+
// Create the validator
24+
$paramsValidator = new JsonRpcParamsValidator(
25+
(new ValidatorBuilder())->getValidator()
26+
);
27+
28+
// Validate a given JSON-RPC method instance against a JSON-RPC request
29+
$violationList = $paramsValidator->validate($jsonRpcRequest, $jsonRpcMethod);
30+
```
31+
32+
Each violations will have the following format :
33+
```php
34+
[
35+
'path' => 'property_path',
36+
'message' => 'violation message',
37+
'code' => 'violation_code'
38+
]
39+
```
1440

1541
## Contributing
1642
See [contributing note](./CONTRIBUTING.md)

0 commit comments

Comments
 (0)