Skip to content

Commit 23464b1

Browse files
authored
Improve (#10)
Fix #9
1 parent 980b0e9 commit 23464b1

File tree

11 files changed

+60
-83
lines changed

11 files changed

+60
-83
lines changed

features/demo_app/default_config/routes.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@
22
# And configure the controller
33
homepage:
44
path: /my-json-rpc-endpoint
5-
defaults: { _controller: 'yoanm.jsonrpc_http_server.endpoint:index' }
5+
defaults: { _controller: 'json_rpc_http_server.endpoint:index' }

features/demo_app/default_config/services.yaml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,14 @@ services:
55
class: DemoApp\Method\MethodA
66
public: true
77
tags:
8-
- { name: 'yoanm.jsonrpc_http_server.jsonrpc_method', method: 'defaultMethodA' }
9-
- { name: 'yoanm.jsonrpc_http_server.jsonrpc_method', method: 'defaultMethodAAlias' }
8+
- { name: 'json_rpc_http_server.jsonrpc_method', method: 'defaultMethodA' }
9+
- { name: 'json_rpc_http_server.jsonrpc_method', method: 'defaultMethodAAlias' }
1010
# Configure Json-RPC method MethodB with tag also
1111
jsonrpc.method.b:
1212
class: DemoApp\Method\MethodB
1313
public: true
1414
tags:
15-
- { name: 'yoanm.jsonrpc_http_server.jsonrpc_method', method: 'defaultMethodB' }
15+
- { name: 'json_rpc_http_server.jsonrpc_method', method: 'defaultMethodB' }
1616

1717
# Configure Json-RPC method MethodC as simple service, it will be injected on container building
1818
jsonrpc.method.c:

features/demo_app/default_config_with_bundle/routes.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@
22
# And configure the controller
33
homepage:
44
path: /my-json-rpc-endpoint
5-
defaults: { _controller: 'yoanm.jsonrpc_http_server.endpoint:index' }
5+
defaults: { _controller: 'json_rpc_http_server.endpoint:index' }

features/demo_app/default_config_with_bundle/services.yaml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,14 @@ services:
55
class: DemoApp\Method\MethodA
66
public: true
77
tags:
8-
- { name: 'yoanm.jsonrpc_http_server.jsonrpc_method', method: 'bundledMethodA' }
9-
- { name: 'yoanm.jsonrpc_http_server.jsonrpc_method', method: 'bundledMethodAAlias' }
8+
- { name: 'json_rpc_http_server.jsonrpc_method', method: 'bundledMethodA' }
9+
- { name: 'json_rpc_http_server.jsonrpc_method', method: 'bundledMethodAAlias' }
1010
# Configure Json-RPC method MethodB with tag also
1111
jsonrpc.method.b:
1212
class: DemoApp\Method\MethodB
1313
public: true
1414
tags:
15-
- { name: 'yoanm.jsonrpc_http_server.jsonrpc_method', method: 'bundledMethodB' }
15+
- { name: 'json_rpc_http_server.jsonrpc_method', method: 'bundledMethodB' }
1616

1717
# Configure Json-RPC method MethodC as simple service, it will be injected on container building
1818
jsonrpc.method.c:

features/demo_app/default_config_with_bundle_and_resolver/routes.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@
22
# And configure the controller
33
homepage:
44
path: /my-json-rpc-endpoint
5-
defaults: { _controller: 'yoanm.jsonrpc_http_server.endpoint:index' }
5+
defaults: { _controller: 'json_rpc_http_server.endpoint:index' }

features/demo_app/default_config_with_resolver/routes.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@
22
# And configure the controller
33
homepage:
44
path: /my-json-rpc-endpoint
5-
defaults: { _controller: 'yoanm.jsonrpc_http_server.endpoint:index' }
5+
defaults: { _controller: 'json_rpc_http_server.endpoint:index' }

features/demo_app/default_config_with_resolver/services.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ services:
1919
##### Configure your resolver and add the required tag
2020
jsonrpc.custom_method_resolver:
2121
class: DemoApp\Resolver\JsonRpcMethodResolver
22-
tags: ['yoanm.jsonrpc_http_server.method_resolver']
22+
tags: ['json_rpc_http_server.method_resolver']
2323

2424
# Inject your JSON-RPC methods (They cannot be automatically injected as resolver implementation is on your own)
2525
calls:

features/symfony-extension.feature

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ Feature: Symfony extension
66
And there is a public "my_service.method.method_name" JSON-RPC method service
77
And there is a public "my_service.method.another" JSON-RPC method service
88
And there is a public "my_service.method.dummy" JSON-RPC method service
9-
When I load endpoint from "yoanm.jsonrpc_http_server.endpoint" service
9+
When I load endpoint from "json_rpc_http_server.endpoint" service
1010
And I inject my "my-method-name" to "my_service.method.method_name" JSON-RPC mapping into default method resolver instance
1111
# Bind same service a second time
1212
And I inject my "my-method-alias" to "my_service.method.method_name" JSON-RPC mapping into default method resolver instance
@@ -28,7 +28,7 @@ Feature: Symfony extension
2828
And I inject my "my-method-alias" to "my_service.method.method_name" JSON-RPC mapping into default method resolver definition
2929
And I inject my "an-another-method" to "my_service.method.another" JSON-RPC mapping into default method resolver definition
3030
And I inject my "getDummy" to "my_service.method.dummy" JSON-RPC mapping into default method resolver definition
31-
When I load endpoint from "yoanm.jsonrpc_http_server.endpoint" service
31+
When I load endpoint from "json_rpc_http_server.endpoint" service
3232
Then endpoint should respond to following JSON-RPC methods:
3333
| getDummy |
3434
| my-method-name |
@@ -37,9 +37,9 @@ Feature: Symfony extension
3737

3838
@symfony-method-resolver-tag
3939
Scenario: Use a custom method resolver
40-
Given I tag my custom method resolver service with "yoanm.jsonrpc_http_server.method_resolver"
40+
Given I tag my custom method resolver service with "json_rpc_http_server.method_resolver"
4141
And I process the symfony extension
42-
When I load endpoint from "yoanm.jsonrpc_http_server.endpoint" service
42+
When I load endpoint from "json_rpc_http_server.endpoint" service
4343
And I inject my "doSomething" JSON-RPC method into my custom method resolver instance
4444
And I inject my "doAnotherThing" JSON-RPC method into my custom method resolver instance
4545
And I inject my "doALastThing" JSON-RPC method into my custom method resolver instance
@@ -50,33 +50,33 @@ Feature: Symfony extension
5050

5151
@symfony-method-resolver-tag
5252
Scenario: Use a custom method resolver with json-rpc methods container injection
53-
Given I tag my custom method resolver service with "yoanm.jsonrpc_http_server.method_resolver"
53+
Given I tag my custom method resolver service with "json_rpc_http_server.method_resolver"
5454
And I process the symfony extension
5555
And I inject my "doSomething" JSON-RPC method into my custom method resolver definition
5656
And I inject my "doAnotherThing" JSON-RPC method into my custom method resolver definition
5757
And I inject my "doALastThing" JSON-RPC method into my custom method resolver definition
58-
When I load endpoint from "yoanm.jsonrpc_http_server.endpoint" service
58+
When I load endpoint from "json_rpc_http_server.endpoint" service
5959
Then endpoint should respond to following JSON-RPC methods:
6060
| doAnotherThing |
6161
| doALastThing |
6262
| doSomething |
6363

6464
@symfony-jsonrpc-method-tag
6565
Scenario: Define json-rpc method with tags
66-
Given I have a JSON-RPC method service definition with "yoanm.jsonrpc_http_server.jsonrpc_method" tag and following tag attributes:
66+
Given I have a JSON-RPC method service definition with "json_rpc_http_server.jsonrpc_method" tag and following tag attributes:
6767
"""
6868
{"method": "my-method-name"}
6969
"""
70-
And I have a JSON-RPC method service definition with "yoanm.jsonrpc_http_server.jsonrpc_method" tag and following tag attributes:
70+
And I have a JSON-RPC method service definition with "json_rpc_http_server.jsonrpc_method" tag and following tag attributes:
7171
"""
7272
{"method": "an-another-method"}
7373
"""
74-
And I have a JSON-RPC method service definition with "yoanm.jsonrpc_http_server.jsonrpc_method" tag and following tag attributes:
74+
And I have a JSON-RPC method service definition with "json_rpc_http_server.jsonrpc_method" tag and following tag attributes:
7575
"""
7676
{"method": "getDummy"}
7777
"""
7878
And I process the symfony extension
79-
When I load endpoint from "yoanm.jsonrpc_http_server.endpoint" service
79+
When I load endpoint from "json_rpc_http_server.endpoint" service
8080
Then endpoint should respond to following JSON-RPC methods:
8181
| getDummy |
8282
| my-method-name |

src/Infra/Symfony/DependencyInjection/JsonRpcHttpServerExtension.php

Lines changed: 32 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -30,38 +30,25 @@
3030
class JsonRpcHttpServerExtension implements ExtensionInterface, CompilerPassInterface
3131
{
3232
// Use this service to inject string request
33-
const ENDPOINT_SERVICE_NAME = 'yoanm.jsonrpc_http_server.endpoint';
33+
const ENDPOINT_SERVICE_NAME = 'json_rpc_http_server.endpoint';
3434

3535
// Use this tag to inject your own resolver
36-
const METHOD_RESOLVER_TAG = 'yoanm.jsonrpc_http_server.method_resolver';
36+
const METHOD_RESOLVER_TAG = 'json_rpc_http_server.method_resolver';
3737

3838
// Use this tag to inject your JSON-RPC methods into the default method resolver
39-
const JSONRPC_METHOD_TAG = 'yoanm.jsonrpc_http_server.jsonrpc_method';
39+
const JSONRPC_METHOD_TAG = 'json_rpc_http_server.jsonrpc_method';
4040

4141
// In case you want to add mapping for a method, use the following service
42-
const SERVICE_NAME_RESOLVER_SERVICE_NAME = 'yoanm.jsonrpc_http_server.resolver.service_name';
42+
const SERVICE_NAME_RESOLVER_SERVICE_NAME = 'json_rpc_http_server.resolver.service_name';
4343
// And add an attribute with following key
4444
const JSONRPC_METHOD_TAG_METHOD_NAME_KEY = 'method';
4545

4646
// Extension identifier (used in configuration for instance)
4747
const EXTENSION_IDENTIFIER = 'json_rpc_http_server';
4848

4949

50-
private $sdkAppResponseCreatorServiceId = 'sdk.app.creator.response';
51-
private $sdkAppCustomExceptionCreatorServiceId = 'sdk.app.creator.custom_exception';
52-
private $sdkAppRequestDenormalizerServiceId = 'sdk.app.serialization.request_denormalizer';
53-
private $sdkAppResponseNormalizerServiceId = 'sdk.app.serialization.response_normalizer';
54-
private $sdkAppMethodManagerServiceId = 'sdk.app.manager.method';
55-
private $sdkAppRequestHandlerServiceId = 'sdk.app.handler.request';
56-
57-
private $sdkInfraEndpointServiceId = 'sdk.infra.endpoint';
58-
private $sdkInfraRawReqSerializerServiceId = 'sdk.infra.serialization.raw_request_serializer';
59-
private $sdkInfraRawRespSerializerServiceId = 'sdk.infra.serialization.raw_response_serializer';
60-
61-
private $psr11InfraMethodResolverServiceId = 'psr11.infra.resolver.method';
62-
63-
private $methodResolverStubServiceId = 'infra.resolver.method';
64-
private $customResolverContainerParameter = self::EXTENSION_IDENTIFIER.'.custom_method_resolver';
50+
/** Private constants */
51+
const CUSTOM_METHOD_RESOLVER_CONTAINER_PARAM = self::EXTENSION_IDENTIFIER.'.custom_method_resolver';
6552

6653
/** @var bool */
6754
private $parseConfig = false;
@@ -130,44 +117,44 @@ protected function createAppServiceDefinitions(ContainerBuilder $container)
130117
{
131118
// RequestDenormalizer
132119
$container->setDefinition(
133-
$this->prependServiceName($this->sdkAppRequestDenormalizerServiceId),
120+
'json_rpc_http_server.sdk.app.serialization.request_denormalizer',
134121
new Definition(RequestDenormalizer::class)
135122
);
136123
// ResponseNormalizer
137124
$container->setDefinition(
138-
$this->prependServiceName($this->sdkAppResponseNormalizerServiceId),
125+
'json_rpc_http_server.sdk.app.serialization.response_normalizer',
139126
new Definition(ResponseNormalizer::class)
140127
);
141128
// ResponseCreator
142129
$container->setDefinition(
143-
$this->prependServiceName($this->sdkAppResponseCreatorServiceId),
130+
'json_rpc_http_server.sdk.app.creator.response',
144131
new Definition(ResponseCreator::class)
145132
);
146133
// CustomExceptionCreator
147134
$container->setDefinition(
148-
$this->prependServiceName($this->sdkAppCustomExceptionCreatorServiceId),
135+
'json_rpc_http_server.sdk.app.creator.custom_exception',
149136
new Definition(CustomExceptionCreator::class)
150137
);
151138

152139
// MethodManager
153140
$container->setDefinition(
154-
$this->prependServiceName($this->sdkAppMethodManagerServiceId),
141+
'json_rpc_http_server.sdk.app.manager.method',
155142
new Definition(
156143
MethodManager::class,
157144
[
158-
new Reference($this->prependServiceName($this->methodResolverStubServiceId)),
159-
new Reference($this->prependServiceName($this->sdkAppCustomExceptionCreatorServiceId))
145+
new Reference('json_rpc_http_server.infra.resolver.method'),
146+
new Reference('json_rpc_http_server.sdk.app.creator.custom_exception')
160147
]
161148
)
162149
);
163150
// RequestHandler
164151
$container->setDefinition(
165-
$this->prependServiceName($this->sdkAppRequestHandlerServiceId),
152+
'json_rpc_http_server.sdk.app.handler.request',
166153
new Definition(
167154
RequestHandler::class,
168155
[
169-
new Reference($this->prependServiceName($this->sdkAppMethodManagerServiceId)),
170-
new Reference($this->prependServiceName($this->sdkAppResponseCreatorServiceId))
156+
new Reference('json_rpc_http_server.sdk.app.manager.method'),
157+
new Reference('json_rpc_http_server.sdk.app.creator.response')
171158
]
172159
)
173160
);
@@ -180,37 +167,37 @@ protected function createInfraServiceDefinitions(ContainerBuilder $container)
180167
{
181168
// RawRequestSerializer
182169
$container->setDefinition(
183-
$this->prependServiceName($this->sdkInfraRawReqSerializerServiceId),
170+
'json_rpc_http_server.sdk.infra.serialization.raw_request_serializer',
184171
new Definition(
185172
RawRequestSerializer::class,
186-
[new Reference($this->prependServiceName($this->sdkAppRequestDenormalizerServiceId))]
173+
[new Reference('json_rpc_http_server.sdk.app.serialization.request_denormalizer')]
187174
)
188175
);
189176

190177
// RawResponseSerializer
191178
$container->setDefinition(
192-
$this->prependServiceName($this->sdkInfraRawRespSerializerServiceId),
179+
'json_rpc_http_server.sdk.infra.serialization.raw_response_serializer',
193180
new Definition(
194181
RawResponseSerializer::class,
195-
[new Reference($this->prependServiceName($this->sdkAppResponseNormalizerServiceId))]
182+
[new Reference('json_rpc_http_server.sdk.app.serialization.response_normalizer')]
196183
)
197184
);
198185
// JsonRpcEndpoint
199186
$container->setDefinition(
200-
$this->prependServiceName($this->sdkInfraEndpointServiceId),
187+
'json_rpc_http_server.sdk.infra.endpoint',
201188
new Definition(
202189
JsonRpcEndpoint::class,
203190
[
204-
new Reference($this->prependServiceName($this->sdkInfraRawReqSerializerServiceId)),
205-
new Reference($this->prependServiceName($this->sdkAppRequestHandlerServiceId)),
206-
new Reference($this->prependServiceName($this->sdkInfraRawRespSerializerServiceId)),
207-
new Reference($this->prependServiceName($this->sdkAppResponseCreatorServiceId))
191+
new Reference('json_rpc_http_server.sdk.infra.serialization.raw_request_serializer'),
192+
new Reference('json_rpc_http_server.sdk.app.handler.request'),
193+
new Reference('json_rpc_http_server.sdk.infra.serialization.raw_response_serializer'),
194+
new Reference('json_rpc_http_server.sdk.app.creator.response')
208195
]
209196
)
210197
);
211198
// ContainerMethodResolver
212199
$container->setDefinition(
213-
$this->prependServiceName($this->psr11InfraMethodResolverServiceId),
200+
'json_rpc_http_server.psr11.infra.resolver.method',
214201
(new Definition(
215202
ContainerMethodResolver::class,
216203
[
@@ -236,7 +223,7 @@ protected function createPublicServiceDefinitions(ContainerBuilder $container)
236223
(new Definition(
237224
JsonRpcHttpEndpoint::class,
238225
[
239-
new Reference($this->prependServiceName($this->sdkInfraEndpointServiceId))
226+
new Reference('json_rpc_http_server.sdk.infra.endpoint')
240227
]
241228
))->setPublic(true)
242229
);
@@ -255,8 +242,8 @@ protected function createPublicServiceDefinitions(ContainerBuilder $container)
255242
private function aliasMethodResolver(ContainerBuilder $container)
256243
{
257244
$isContainerResolver = false;
258-
if ($container->hasParameter($this->customResolverContainerParameter)) {
259-
$resolverServiceId = $container->getParameter($this->customResolverContainerParameter);
245+
if ($container->hasParameter(self::CUSTOM_METHOD_RESOLVER_CONTAINER_PARAM)) {
246+
$resolverServiceId = $container->getParameter(self::CUSTOM_METHOD_RESOLVER_CONTAINER_PARAM);
260247
} else {
261248
$serviceIdList = array_keys($container->findTaggedServiceIds(self::METHOD_RESOLVER_TAG));
262249
$serviceCount = count($serviceIdList);
@@ -273,12 +260,12 @@ private function aliasMethodResolver(ContainerBuilder $container)
273260
$resolverServiceId = array_shift($serviceIdList);
274261
} else {
275262
// Use ArrayMethodResolver as default resolver
276-
$resolverServiceId = $this->prependServiceName($this->psr11InfraMethodResolverServiceId);
263+
$resolverServiceId = 'json_rpc_http_server.psr11.infra.resolver.method';
277264
$isContainerResolver = true;
278265
}
279266
}
280267

281-
$container->setAlias($this->prependServiceName($this->methodResolverStubServiceId), $resolverServiceId);
268+
$container->setAlias('json_rpc_http_server.infra.resolver.method', $resolverServiceId);
282269

283270
return $isContainerResolver;
284271
}
@@ -301,16 +288,6 @@ private function loadJsonRpcMethodsFromTag(ContainerBuilder $container)
301288
}
302289
}
303290

304-
/**
305-
* @param string $serviceName
306-
*
307-
* @return string
308-
*/
309-
private function prependServiceName(string $serviceName) : string
310-
{
311-
return sprintf('yoanm.jsonrpc_http_server.%s', $serviceName);
312-
}
313-
314291
/**
315292
* @param array $tagAttributeList
316293
* @param string $serviceId
@@ -360,7 +337,7 @@ private function compileAndProcessConfigurations(array $configs, ContainerBuilde
360337
$config = (new Processor())->processConfiguration($configuration, $configs);
361338

362339
if (array_key_exists('method_resolver', $config) && $config['method_resolver']) {
363-
$container->setParameter($this->customResolverContainerParameter, $config['method_resolver']);
340+
$container->setParameter(self::CUSTOM_METHOD_RESOLVER_CONTAINER_PARAM, $config['method_resolver']);
364341
}
365342
}
366343
}

tests/Common/Infra/Symfony/DependencyInjection/AbstractTestClass.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,17 +9,17 @@
99
abstract class AbstractTestClass extends AbstractExtensionTestCase
1010
{
1111
// Public services
12-
const EXPECTED_ENDPOINT_SERVICE_ID = 'yoanm.jsonrpc_http_server.endpoint';
13-
const EXPECTED_SERVICE_NAME_RESOLVER_SERVICE_ID = 'yoanm.jsonrpc_http_server.resolver.service_name';
12+
const EXPECTED_ENDPOINT_SERVICE_ID = 'json_rpc_http_server.endpoint';
13+
const EXPECTED_SERVICE_NAME_RESOLVER_SERVICE_ID = 'json_rpc_http_server.resolver.service_name';
1414

1515
// Public tags
16-
const EXPECTED_METHOD_RESOLVER_TAG = 'yoanm.jsonrpc_http_server.method_resolver';
17-
const EXPECTED_JSONRPC_METHOD_TAG = 'yoanm.jsonrpc_http_server.jsonrpc_method';
16+
const EXPECTED_METHOD_RESOLVER_TAG = 'json_rpc_http_server.method_resolver';
17+
const EXPECTED_JSONRPC_METHOD_TAG = 'json_rpc_http_server.jsonrpc_method';
1818

1919
const EXPECTED_JSONRPC_METHOD_TAG_METHOD_NAME_KEY = 'method';
2020

21-
const EXPECTED_METHOD_MANAGER_SERVICE_ID = 'yoanm.jsonrpc_http_server.sdk.app.manager.method';
22-
const EXPECTED_METHOD_RESOLVER_STUB_SERVICE_ID = 'yoanm.jsonrpc_http_server.infra.resolver.method';
21+
const EXPECTED_METHOD_MANAGER_SERVICE_ID = 'json_rpc_http_server.sdk.app.manager.method';
22+
const EXPECTED_METHOD_RESOLVER_STUB_SERVICE_ID = 'json_rpc_http_server.infra.resolver.method';
2323

2424
/**
2525
* {@inheritdoc}

0 commit comments

Comments
 (0)