Skip to content

Commit feba1d5

Browse files
authored
Update README.md
1 parent 05444e1 commit feba1d5

File tree

1 file changed

+45
-8
lines changed

1 file changed

+45
-8
lines changed

README.md

Lines changed: 45 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,17 @@ Symfony bundle for [`yoanm/jsonrpc-server-sdk`](https://raw.githubusercontent.co
1313

1414
## How to use
1515

16-
Bundle requires only two things :
17-
- A method resolver which is compatible with [`yoanm/jsonrpc-server-sdk`](https://raw.githubusercontent.com/yoanm/php-jsonrpc-server-sdk)
16+
Once configured, your project is ready to handle HTTP `POST` request on `/json-rpc` endpoint.
17+
18+
See below how to configure it.
19+
20+
## Configuration
21+
22+
Bundle requires only one things :
1823
- JSON-RPC Methods which are compatible with [`yoanm/jsonrpc-server-sdk`](https://raw.githubusercontent.com/yoanm/php-jsonrpc-server-sdk)
1924

25+
It comes with [built-in method resolver](./src/Resolver/MethodResolver.php) which use a [service locator](https://symfony.com/doc/3.4/service_container/service_subscribers_locators.html#defining-a-service-locator). Using a service locator allow to load (and so instanciate dependencies, dependencies of dependencies, etc) method only when required (usually only one method is required by request, except for batch requests which will load one or more methods).
26+
2027
*[Behat demo app configuration folders](./features/demo_app/) can be used as examples.*
2128

2229
- Add the bundles in your `config/bundles.php` file:
@@ -46,10 +53,10 @@ Bundle requires only two things :
4653
json_rpc_http_server: ~
4754
# Or the following in case you want to customize endpoint path
4855
#json_rpc_http_server:
49-
# endpoint: '/my-custom-endpoint'
56+
# endpoint: '/my-custom-endpoint' # Default to '/json-rpc'
5057
```
5158

52-
## JSON-RPC Method mapping
59+
### JSON-RPC Method mapping
5360
In order to inject yours JSON-RPC method into the server add the tag `json_rpc_http_server.jsonrpc_method` and the key/value `method` like following example :
5461
```yaml
5562
services:
@@ -60,19 +67,49 @@ services:
6067
- { name: 'json_rpc_http_server.jsonrpc_method', method: 'method-a-alias' }
6168
```
6269
63-
64-
## Method resolver
70+
### Methods mapping aware
71+
In case you want to be aware of which methods are registered inside the JSON-RPC server, you can use the `json_rpc_http_server.method_aware`. Your class must implements `JsonRpcMethodAwareInterface`.
72+
73+
```php
74+
use Yoanm\JsonRpcServer\Domain\JsonRpcMethodAwareInterface;
75+
use Yoanm\JsonRpcServer\Domain\JsonRpcMethodInterface;
6576
66-
A method resolver is required, you can either use [`yoanm/symfony-jsonrpc-server-psr11-resolver`](https://github.com/yoanm/symfony-jsonrpc-server-psr11-resolver) or write your own
77+
class MappingCollector implements JsonRpcMethodAwareInterface
78+
{
79+
/** @var JsonRpcMethodInterface[] */
80+
private $mappingList = [];
6781
68-
In case you want to use your own, it will be automatically injected if you use the tag `json_rpc_http_server.method_resolver` :
82+
public function addJsonRpcMethod(string $methodName, JsonRpcMethodInterface $method): void
83+
{
84+
$this->mappingList[$methodName] = $method;
85+
}
86+
87+
/**
88+
* @return JsonRpcMethodInterface[]
89+
*/
90+
public function getMappingList() : array
91+
{
92+
return $this->mappingList;
93+
}
94+
}
95+
```
96+
97+
```yaml
98+
mapping_aware_service:
99+
class: App\Collector\MappingCollector
100+
tags: ['json_rpc_http_server.method_aware']
101+
```
102+
103+
### Custom method resolver
104+
In case you want to use your method resolver implementation, use the tag `json_rpc_http_server.method_resolver`, it will be automatically injected inside JSON-RPC server:
69105
```yaml
70106
services:
71107
my.custom_method_resolver.service:
72108
class: Custom\Method\Resolver\Class
73109
tags: ['json_rpc_http_server.method_resolver']
74110
```
75111

112+
You can take advantage of method mapping aware mechanism or write your custom resolution logic.
76113

77114
## Contributing
78115
See [contributing note](./CONTRIBUTING.md)

0 commit comments

Comments
 (0)