Skip to content

Commit 014bac6

Browse files
authored
Add http endpoint path configuration (#15)
1 parent 28dea3c commit 014bac6

File tree

7 files changed

+41
-6
lines changed

7 files changed

+41
-6
lines changed

features/demo-app.feature

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -89,23 +89,23 @@ Feature: demo symfony application
8989
Scenario: Use Bundle with default method resolver with JSON-RPC method tags
9090
Given DemoApp will use JsonRpcHttpServerBundle
9191
# Ensure the two methods with tag have been loaded
92-
When I send following "POST" input on "/json-rpc" demoApp kernel endpoint:
92+
When I send following "POST" input on "/my-custom-endpoint" demoApp kernel endpoint:
9393
"""
9494
{"jsonrpc": "2.0", "method": "bundledMethodA", "id": 1}
9595
"""
9696
Then I should have a "200" response from demoApp with following content:
9797
"""
9898
{"jsonrpc":"2.0", "result":"MethodA", "id":1}
9999
"""
100-
When I send following "POST" input on "/json-rpc" demoApp kernel endpoint:
100+
When I send following "POST" input on "/my-custom-endpoint" demoApp kernel endpoint:
101101
"""
102102
{"jsonrpc": "2.0", "method": "bundledMethodAAlias", "id": 2}
103103
"""
104104
Then I should have a "200" response from demoApp with following content:
105105
"""
106106
{"jsonrpc":"2.0", "result":"MethodA", "id":2}
107107
"""
108-
When I send following "POST" input on "/json-rpc" demoApp kernel endpoint:
108+
When I send following "POST" input on "/my-custom-endpoint" demoApp kernel endpoint:
109109
"""
110110
{"jsonrpc": "2.0", "method": "bundledMethodB", "id": 3}
111111
"""
@@ -118,15 +118,15 @@ Feature: demo symfony application
118118
Scenario: Use Bundle with default method resolver with JSON-RPC methods container injection
119119
Given DemoApp will use JsonRpcHttpServerBundle
120120
# Ensure the two injected methods have been injected
121-
When I send following "POST" input on "/json-rpc" demoApp kernel endpoint:
121+
When I send following "POST" input on "/my-custom-endpoint" demoApp kernel endpoint:
122122
"""
123123
{"jsonrpc": "2.0", "method": "bundledGetDummy", "id": 1}
124124
"""
125125
Then I should have a "200" response from demoApp with following content:
126126
"""
127127
{"jsonrpc":"2.0", "result":"MethodC", "id":1}
128128
"""
129-
When I send following "POST" input on "/json-rpc" demoApp kernel endpoint:
129+
When I send following "POST" input on "/my-custom-endpoint" demoApp kernel endpoint:
130130
"""
131131
{"jsonrpc": "2.0", "method": "bundledGetAnotherDummy", "id": 2}
132132
"""

features/demo_app/default_config_with_bundle/config.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ framework:
22
secret: '%env(APP_SECRET)%'
33

44
json_rpc_http_server:
5+
http_endpoint_path: '/my-custom-endpoint'
56
methods_mapping:
67
bundledMethodA:
78
service: '@jsonrpc.method.a'

src/DependencyInjection/Configuration.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,10 @@ public function getConfigTreeBuilder()
1414

1515
$rootNode
1616
->children()
17+
->variableNode('http_endpoint_path')
18+
->info('Your custom http endpoint path')
19+
->defaultValue(JsonRpcHttpServerExtension::HTTP_ENDPOINT_PATH)
20+
->end()
1721
->variableNode('method_resolver')
1822
->info('Your custom method resolver service')
1923
->treatNullLike(false)

src/DependencyInjection/JsonRpcHttpServerExtension.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -347,6 +347,7 @@ private function checkJsonRpcMethodService(ContainerBuilder $container, string $
347347
*/
348348
private function compileAndProcessConfigurations(array $configs, ContainerBuilder $container)
349349
{
350+
$httpEndpointPath = self::HTTP_ENDPOINT_PATH;
350351
if (true === $this->parseConfig) {
351352
$configuration = new Configuration();
352353
$config = (new Processor())->processConfiguration($configuration, $configs);
@@ -360,9 +361,12 @@ private function compileAndProcessConfigurations(array $configs, ContainerBuilde
360361
if (array_key_exists('methods_mapping', $config) && is_array($config['methods_mapping'])) {
361362
$container->setParameter(self::METHODS_MAPPING_CONTAINER_PARAM, $config['methods_mapping']);
362363
}
364+
if (array_key_exists('http_endpoint_path', $config)) {
365+
$httpEndpointPath = $config['http_endpoint_path'];
366+
}
363367
}
364368

365-
$container->setParameter(self::HTTP_ENDPOINT_PATH_CONTAINER_PARAM, self::HTTP_ENDPOINT_PATH);
369+
$container->setParameter(self::HTTP_ENDPOINT_PATH_CONTAINER_PARAM, $httpEndpointPath);
366370
}
367371

368372
/**

tests/Common/DependencyInjection/AbstractTestClass.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ abstract class AbstractTestClass extends AbstractExtensionTestCase
2121
const EXPECTED_METHOD_MANAGER_SERVICE_ID = 'json_rpc_http_server.sdk.app.manager.method';
2222
const EXPECTED_METHOD_RESOLVER_STUB_SERVICE_ID = 'json_rpc_http_server.infra.resolver.method';
2323

24+
const EXPECTED_HTTP_ENDPOINT_PATH_CONTAINER_PARAM = 'json_rpc_http_server.http_endpoint_path';
25+
2426
/**
2527
* {@inheritdoc}
2628
*/

tests/Functional/DependencyInjection/JsonRpcHttpServerExtensionWithConfigParsedTest.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,17 @@ protected function getContainerExtensions()
2020
];
2121
}
2222

23+
public function testShouldManageCustomEndpointPathFromConfiguration()
24+
{
25+
$myCustomEndpoint = 'my-custom-endpoint';
26+
$this->load(['http_endpoint_path' => $myCustomEndpoint]);
27+
28+
// Assert custom resolver is an alias of the stub
29+
$this->assertContainerBuilderHasParameter(self::EXPECTED_HTTP_ENDPOINT_PATH_CONTAINER_PARAM, $myCustomEndpoint);
30+
31+
$this->assertEndpointIsUsable();
32+
}
33+
2334
public function testShouldManageCustomResolverFromConfiguration()
2435
{
2536
$myCustomResolverServiceId = 'my-custom-resolver';

tests/Technical/DependencyInjection/JsonRpcHttpServerExtensionWithConfigurationParsedTest.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,19 @@ protected function getContainerExtensions()
2020
];
2121
}
2222

23+
public function testShouldHaveADefaultEndpointConfigured()
24+
{
25+
$this->load();
26+
27+
// Assert custom resolver is an alias of the stub
28+
$this->assertContainerBuilderHasParameter(
29+
self::EXPECTED_HTTP_ENDPOINT_PATH_CONTAINER_PARAM,
30+
JsonRpcHttpServerExtension::HTTP_ENDPOINT_PATH
31+
);
32+
33+
$this->assertEndpointIsUsable();
34+
}
35+
2336
public function testShouldNormalizeExternalServiceIdStringPassedForMethodResolver()
2437
{
2538
$myCustomResolverServiceId = 'my-custom-resolver';

0 commit comments

Comments
 (0)