Skip to content

Commit 43f37df

Browse files
authored
Update README.md
1 parent 8f71172 commit 43f37df

File tree

1 file changed

+38
-0
lines changed

1 file changed

+38
-0
lines changed

README.md

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,46 @@
99

1010
PHP SDK to generate JSON-RPC documentation from symfony constraint
1111

12+
See [yoanm/symfony-jsonrpc-params-sf-constraints-doc](https://github.com/yoanm/symfony-jsonrpc-params-sf-constraints-doc) for automatic dependency injection.
13+
1214
## How to use
1315

16+
Create the transformer :
17+
```php
18+
$constraintPayloadDocHelper = new ConstraintPayloadDocHelper();
19+
20+
$transformer = new ConstraintToParamsDocTransformer(
21+
new DocTypeHelper(
22+
$constraintPayloadDocHelper,
23+
new TypeGuesser()
24+
),
25+
new StringDocHelper(),
26+
new MinMaxHelper(),
27+
$constraintPayloadDocHelper
28+
);
29+
```
30+
31+
Then use it with single constraint or a list of :
32+
```php
33+
use Symfony\Component\Validator\Constraints as ConstraintNS;
34+
use Yoanm\JsonRpcServerDoc\Domain\Model\Type\ObjectDoc;
35+
use Yoanm\JsonRpcServerDoc\Domain\Model\Type\StringDoc;
36+
37+
$constraint = new ConstraintNS\Collection([
38+
'a' => new ConstraintNS\Type('string'),
39+
'b' => new ConstraintNS\Type('integer'),
40+
'c' => new ConstraintNS\Type('bool')
41+
]);
42+
43+
/** @var ObjectDoc $constraintDoc */
44+
$constraintDoc = $transformer->transform($constraint);
45+
46+
/** @var StringDoc $constraintDoc2 */
47+
$constraintDoc2 = $transformer->transformList([
48+
new ConstraintNS\Type('string'),
49+
new ConstraintNS\NotNull()
50+
]);
51+
```
1452

1553
## Contributing
1654
See [contributing note](./CONTRIBUTING.md)

0 commit comments

Comments
 (0)