Skip to content

Commit 28dea3c

Browse files
authored
Add default routing file (#14)
Fix #7
1 parent ec1f49d commit 28dea3c

File tree

6 files changed

+42
-19
lines changed

6 files changed

+42
-19
lines changed

features/demo-app.feature

Lines changed: 9 additions & 9 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 "/my-json-rpc-endpoint" demoApp kernel endpoint:
92+
When I send following "POST" input on "/json-rpc" 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 "/my-json-rpc-endpoint" demoApp kernel endpoint:
100+
When I send following "POST" input on "/json-rpc" 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 "/my-json-rpc-endpoint" demoApp kernel endpoint:
108+
When I send following "POST" input on "/json-rpc" 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 "/my-json-rpc-endpoint" demoApp kernel endpoint:
121+
When I send following "POST" input on "/json-rpc" 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 "/my-json-rpc-endpoint" demoApp kernel endpoint:
129+
When I send following "POST" input on "/json-rpc" demoApp kernel endpoint:
130130
"""
131131
{"jsonrpc": "2.0", "method": "bundledGetAnotherDummy", "id": 2}
132132
"""
@@ -140,31 +140,31 @@ Feature: demo symfony application
140140
Given DemoApp will use JsonRpcHttpServerBundle
141141
And I use my DemoApp custom method resolver
142142
# Ensure all methods have been loaded
143-
When I send following "POST" input on "/my-json-rpc-endpoint" demoApp kernel endpoint:
143+
When I send following "POST" input on "/json-rpc" demoApp kernel endpoint:
144144
"""
145145
{"jsonrpc": "2.0", "method": "customBundledMethodA", "id": 1}
146146
"""
147147
Then I should have a "200" response from demoApp with following content:
148148
"""
149149
{"jsonrpc":"2.0", "result":"MethodA", "id":1}
150150
"""
151-
When I send following "POST" input on "/my-json-rpc-endpoint" demoApp kernel endpoint:
151+
When I send following "POST" input on "/json-rpc" demoApp kernel endpoint:
152152
"""
153153
{"jsonrpc": "2.0", "method": "customBundledMethodB", "id": 2}
154154
"""
155155
Then I should have a "200" response from demoApp with following content:
156156
"""
157157
{"jsonrpc":"2.0", "result":"MethodB", "id":2}
158158
"""
159-
When I send following "POST" input on "/my-json-rpc-endpoint" demoApp kernel endpoint:
159+
When I send following "POST" input on "/json-rpc" demoApp kernel endpoint:
160160
"""
161161
{"jsonrpc": "2.0", "method": "customBundledMethodC", "id": 3}
162162
"""
163163
Then I should have a "200" response from demoApp with following content:
164164
"""
165165
{"jsonrpc":"2.0", "result":"MethodC", "id":3}
166166
"""
167-
When I send following "POST" input on "/my-json-rpc-endpoint" demoApp kernel endpoint:
167+
When I send following "POST" input on "/json-rpc" demoApp kernel endpoint:
168168
"""
169169
{"jsonrpc": "2.0", "method": "customBundledMethodD", "id": 4}
170170
"""
Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
# Configure the HTTP JSON-RPC endpoint on any path
2-
# And configure the controller
3-
homepage:
4-
path: /my-json-rpc-endpoint
5-
defaults: { _controller: 'json_rpc_http_server.endpoint:index' }
1+
# Import default configuration or write your own
2+
json-rpc-endpoint:
3+
resource: '@JsonRpcHttpServerBundle/Resources/config/routing/endpoint.xml'
Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
# Configure the HTTP JSON-RPC endpoint on any path
2-
# And configure the controller
3-
homepage:
4-
path: /my-json-rpc-endpoint
5-
defaults: { _controller: 'json_rpc_http_server.endpoint:index' }
1+
# Import default configuration or write your own
2+
json-rpc-endpoint:
3+
resource: '@JsonRpcHttpServerBundle/Resources/config/routing/endpoint.xml'

features/demo_app/src/AbstractKernel.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
namespace DemoApp;
33

44
use Symfony\Bundle\FrameworkBundle\Kernel\MicroKernelTrait;
5+
use Symfony\Component\DependencyInjection\Container;
56
use Symfony\Component\HttpKernel\Kernel as BaseHttpKernel;
67

78
abstract class AbstractKernel extends BaseHttpKernel
@@ -41,5 +42,16 @@ public function getProjectDir()
4142
return realpath(__DIR__.'/../');
4243
}
4344

45+
/**
46+
* Gets the container class.
47+
*
48+
* @return string The container class
49+
*/
50+
protected function getContainerClass()
51+
{
52+
// In order to avoid collisions between kernels use a dedicated name
53+
return parent::getContainerClass().Container::camelize($this->getConfigDirectory());
54+
}
55+
4456
abstract public function getConfigDirectory() : string;
4557
}

src/DependencyInjection/JsonRpcHttpServerExtension.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,10 +46,13 @@ class JsonRpcHttpServerExtension implements ExtensionInterface, CompilerPassInte
4646
// Extension identifier (used in configuration for instance)
4747
const EXTENSION_IDENTIFIER = 'json_rpc_http_server';
4848

49+
const HTTP_ENDPOINT_PATH = '/json-rpc';
50+
4951

5052
/** Private constants */
5153
const CUSTOM_METHOD_RESOLVER_CONTAINER_PARAM = self::EXTENSION_IDENTIFIER.'.custom_method_resolver';
5254
const METHODS_MAPPING_CONTAINER_PARAM = self::EXTENSION_IDENTIFIER.'.methods_mapping';
55+
const HTTP_ENDPOINT_PATH_CONTAINER_PARAM = self::EXTENSION_IDENTIFIER.'.http_endpoint_path';
5356

5457
/** @var bool */
5558
private $parseConfig = false;
@@ -358,6 +361,8 @@ private function compileAndProcessConfigurations(array $configs, ContainerBuilde
358361
$container->setParameter(self::METHODS_MAPPING_CONTAINER_PARAM, $config['methods_mapping']);
359362
}
360363
}
364+
365+
$container->setParameter(self::HTTP_ENDPOINT_PATH_CONTAINER_PARAM, self::HTTP_ENDPOINT_PATH);
361366
}
362367

363368
/**
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<?xml version="1.0" encoding="UTF-8" ?>
2+
3+
<routes xmlns="http://symfony.com/schema/routing"
4+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
5+
xsi:schemaLocation="http://symfony.com/schema/routing http://symfony.com/schema/routing/routing-1.0.xsd">
6+
7+
<route id="json_rpc_http_server_endpoint" path="%json_rpc_http_server.http_endpoint_path%">
8+
<default key="_controller">json_rpc_http_server.endpoint:index</default>
9+
</route>
10+
</routes>

0 commit comments

Comments
 (0)