You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+45-8Lines changed: 45 additions & 8 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -13,10 +13,17 @@ Symfony bundle for [`yoanm/jsonrpc-server-sdk`](https://raw.githubusercontent.co
13
13
14
14
## How to use
15
15
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 :
18
23
- JSON-RPC Methods which are compatible with [`yoanm/jsonrpc-server-sdk`](https://raw.githubusercontent.com/yoanm/php-jsonrpc-server-sdk)
19
24
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
+
20
27
*[Behat demo app configuration folders](./features/demo_app/) can be used as examples.*
21
28
22
29
- Add the bundles in your `config/bundles.php` file:
@@ -46,10 +53,10 @@ Bundle requires only two things :
46
53
json_rpc_http_server: ~
47
54
# Or the following in case you want to customize endpoint path
48
55
#json_rpc_http_server:
49
-
# endpoint: '/my-custom-endpoint'
56
+
# endpoint: '/my-custom-endpoint' # Default to '/json-rpc'
50
57
```
51
58
52
-
## JSON-RPC Method mapping
59
+
###JSON-RPC Method mapping
53
60
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 :
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;
65
76
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 = [];
67
81
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:
69
105
```yaml
70
106
services:
71
107
my.custom_method_resolver.service:
72
108
class: Custom\Method\Resolver\Class
73
109
tags: ['json_rpc_http_server.method_resolver']
74
110
```
75
111
112
+
You can take advantage of method mapping aware mechanism or write your custom resolution logic.
0 commit comments