@@ -11,17 +11,18 @@ Symfony JSON-RPC HTTP Server to convert an HTTP json-rpc request into HTTP json-
1111
1212## How to use
1313
14- You can either use this library as a simple extension or like any symfony bundle.
15-
14+ Bundle requires only two things :
15+ - A method resolver which is compatible with [ ` yoanm/jsonrpc-server-sdk ` ] ( https://raw.githubusercontent.com/yoanm/php-jsonrpc-server-sdk )
16+ - JSON-RPC Methods which are compatible with [ ` yoanm/jsonrpc-server-sdk ` ] ( https://raw.githubusercontent.com/yoanm/php-jsonrpc-server-sdk )
17+
1618* [ Behat demo app configuration folders] ( ./features/demo_app/ ) can be used as examples.*
1719
18- ### With Symfony bundle
19-
2020 - Add the bundles in your ` config/bundles.php ` file:
2121 ``` php
2222 // config/bundles.php
2323 return [
2424 ...
25+ Symfony\Bundle\FrameworkBundle\FrameworkBundle::class => ['all' => true],
2526 Yoanm\SymfonyJsonRpcHttpServer\JsonRpcHttpServerBundle::class => ['all' => true],
2627 ...
2728 ];
@@ -37,138 +38,39 @@ You can either use this library as a simple extension or like any symfony bundle
3738 - Add the following in your configuration :
3839 ` ` ` yaml
3940 # config/config.yaml
40- json_rpc_http_server : ~
41- ` ` `
41+ framework :
42+ secret : ' %env(APP_SECRET)% '
4243
43- ### With Symfony extension only
44- - Load the extension in your kernel :
45- ` ` ` php
46- // src/Kernel.php
47- ...
48- use Symfony\Bundle\FrameworkBundle\Kernel\MicroKernelTrait;
49- use Yoanm\SymfonyJsonRpcHttpServer\DependencyInjection\JsonRpcHttpServerExtension;
50- ...
51- class Kernel
52- {
53- use MicroKernelTrait;
54- ....
55- /**
56- * {@inheritdoc}
57- */
58- protected function configureContainer(ContainerBuilder $container, LoaderInterface $loader)
59- {
60- /**** Add and load extension **/
61- $container->registerExtension($extension = new JsonRpcHttpServerExtension());
62- // If you use Symfony Config component, add "json_rpc_http_server : ~" in your configuration.
63- // Else load it there
64- $container->loadFromExtension($extension->getAlias());
65-
66- ...
67- }
68- ....
69- }
44+ json_rpc_http_server : ~
45+ # Or the following in case you want to customize endpoint path
46+ # json_rpc_http_server:
47+ # endpoint: '/my-custom-endpoint'
7048 ```
71-
72- - Map your your JSON-RPC methods, see ** JSON-RPC Method mapping** section below
73- - Manually configure an endpoint, see ** Routing** section below
7449
7550## JSON-RPC Method mapping
76- You have many ways to inject you json-rpc methods :
77- - If you use the bundle, you can do it by configuration :
78- ``` yaml
79- # config/config.yaml
80- json_rpc_http_server :
81- methods_mapping :
82- method-a : ' @method-a.service-id'
83- method-b :
84- service : ' @method-b.service-id'
85- aliases : ' method-b-alias'
86- method-c :
87- service : ' @method-c.service-id'
88- aliases : ['method-c-alias-1', 'method-c-alias-2']
89- ` ` `
90- - You can use tag in the service definition as below :
91- ` ` ` yaml
92- services :
93- method-a.service-id :
94- class : Method\A\Class
95- public : true # <= do no forget the set visibility to public !
96- tags :
97- - { name: 'json_rpc_http_server.jsonrpc_method', method: 'method-a' }
98- - { name: 'json_rpc_http_server.jsonrpc_method', method: 'method-a-alias' }
99- ` ` `
100- - Inject manually your mapping during container building
101- ` ` ` php
102- // src/Kernel.php
103- ...
104- use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
105- use Yoanm\SymfonyJsonRpcHttpServer\DependencyInjection\JsonRpcHttpServerExtension;
106- ...
107- class Kernel implements CompilerPassInterface
108- {
109- ....
110- /**
111- * {@inheritdoc}
112- */
113- public function process(ContainerBuilder $container)
114- {
115- $container->getDefinition(JsonRpcHttpServerExtension::SERVICE_NAME_RESOLVER_SERVICE_NAME)
116- ->addMethodCall('addMethodMapping', ['method-a', 'method-a.service-id'])
117- ->addMethodCall('addMethodMapping', ['method-b', 'method-b.service-id'])
118- ->addMethodCall('addMethodMapping', ['method-b-alias', 'method-b.service-id'])
119- ;
120- }
121- ....
122- }
123- ```
124- - Or inject manually your mapping after container building
125- ``` php
126- $container->get(JsonRpcHttpServerExtension::SERVICE_NAME_RESOLVER_SERVICE_NAME)
127- ->addMethodMapping('method-a', 'method-a.service-id')
128- ->addMethodMapping('method-b', 'method-b.service-id')
129- ->addMethodMapping('method-b-alias', 'method-b.service-id')
130- ;
131- ```
132-
133- ## Routing
134- - If you use the bundle, the default endpoint is ` /json-rcp ` . You can custome it by using :
135- ``` yaml
136- # config/config.yaml
137- json_rpc_http_server :
138- endpoint : ' /my-custom-endpoint'
139- ` ` `
140-
141- - Or you can define your own route and bind the endpoint as below :
142- ` ` ` yaml
143- # config/routes.yaml
144- index :
145- path : /my-json-rpc-endpoint
146- defaults : { _controller: 'json_rpc_http_server.endpoint:index' }
147- ` ` `
148-
149- ## Custom method resolver
51+ 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 :
52+ ``` yaml
53+ services :
54+ method-a.service-id :
55+ class : Method\A\Class
56+ tags :
57+ - { name: 'json_rpc_http_server.jsonrpc_method', method: 'method-a' }
58+ - { name: 'json_rpc_http_server.jsonrpc_method', method: 'method-a-alias' }
59+ ` ` `
15060
151- By default this bundle use [` yoanm/jsonrpc-server-sdk-psr11-resolver`](https://github.com/yoanm/php-jsonrpc-server-sdk-psr11-resolver).
61+
62+ ## Method resolver
15263
153- In case you want to use your own , you can do it by using :
64+ 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
15465
155- # ## Service definition tag
156- Use `json_rpc_http_server.method_resolver` tag as following :
66+ In case you want to use your own, it will be automatically injected if you use the tag `json_rpc_http_server.method_resolver` :
15767` ` ` yaml
15868services:
15969 my.custom_method_resolver.service:
16070 class: Custom\M ethod\R esolver\C lass
16171 tags: ['json_rpc_http_server.method_resolver']
16272` ` `
16373
164- # ## Bundle configuration
165- Configure the bundle as below
166- ` ` ` yaml
167- # config/config.yaml
168- json_rpc_http_server:
169- method_resolver: '@my.custom_method_resolver.service'
170- ` ` `
171-
17274
17375# # Contributing
17476See [contributing note](./CONTRIBUTING.md)
0 commit comments