Skip to content

Commit 93e4446

Browse files
committed
Merge branch 'hotfix/3.0.3'
2 parents 33ac883 + 224d9b0 commit 93e4446

File tree

9 files changed

+116
-10
lines changed

9 files changed

+116
-10
lines changed

features/bootstrap/DemoAppContext.php

+29
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@
22
namespace Tests\Functional\BehatContext;
33

44
use Behat\Gherkin\Node\PyStringNode;
5+
use DemoApp\AbstractKernel;
6+
use DemoApp\DefaultKernel;
7+
use DemoApp\KernelWithMappingCollectorListener;
58
use PHPUnit\Framework\Assert;
69
use Symfony\Component\HttpFoundation\Response;
710
use Yoanm\JsonRpcServer\Domain\JsonRpcMethodInterface;
@@ -13,6 +16,16 @@ class DemoAppContext extends AbstractContext
1316
{
1417
/** @var Response|null */
1518
private $lastResponse;
19+
/** @var bool */
20+
private $useKernelWithMappingCollectorListener = false;
21+
22+
/**
23+
* @Given I will use kernel with MappingCollector listener
24+
*/
25+
public function givenIWillUseServerDocCreatedListener()
26+
{
27+
$this->useKernelWithMappingCollectorListener = true;
28+
}
1629

1730
/**
1831
* @When I send following :httpMethod input on :uri demoApp kernel endpoint:
@@ -69,4 +82,20 @@ public function thenCollectorShouldHaveAMethodWithName($methodClass, $methodName
6982
sprintf('Method "%s" is not an instance of "%s"', $methodName, $methodClass)
7083
);
7184
}
85+
/**
86+
* @return AbstractKernel
87+
*/
88+
public function getDemoAppKernel()
89+
{
90+
$env = 'prod';
91+
$debug = true;
92+
93+
if (true === $this->useKernelWithMappingCollectorListener) {
94+
$kernelClass = KernelWithMappingCollectorListener::class;
95+
} else {
96+
$kernelClass = DefaultKernel::class;
97+
}
98+
99+
return new $kernelClass($env, $debug);
100+
}
72101
}

features/demo_app/default_config/services.yaml

-6
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,3 @@ services:
1717
class: DemoApp\Method\MethodD
1818
tags:
1919
- { name: 'json_rpc_http_server.jsonrpc_method', method: 'bundledGetAnotherDummy' }
20-
21-
## Mapping aware service
22-
mapping_aware_service:
23-
public: true # In order to allow Behat context to load it later
24-
class: DemoApp\Collector\MappingCollector
25-
tags: ['json_rpc_http_server.method_aware']
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<?php
2+
return [
3+
Symfony\Bundle\FrameworkBundle\FrameworkBundle::class => ['all' => true],
4+
Yoanm\SymfonyJsonRpcHttpServer\JsonRpcHttpServerBundle::class => ['all' => true],
5+
];
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
framework:
2+
secret: '%env(APP_SECRET)%'
3+
4+
json_rpc_http_server:
5+
endpoint: '/my-custom-endpoint'
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# Import default configuration or write your own
2+
json-rpc-endpoint:
3+
resource: '@JsonRpcHttpServerBundle/Resources/config/routing/endpoint.xml'
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
# Configure JSON-RPC method services.
2+
services:
3+
jsonrpc.method.a:
4+
class: DemoApp\Method\MethodA
5+
tags:
6+
- { name: 'json_rpc_http_server.jsonrpc_method', method: 'bundledMethodA' }
7+
- { name: 'json_rpc_http_server.jsonrpc_method', method: 'bundledMethodAAlias' }
8+
jsonrpc.method.b:
9+
class: DemoApp\Method\MethodB
10+
tags:
11+
- { name: 'json_rpc_http_server.jsonrpc_method', method: 'bundledMethodB' }
12+
jsonrpc.method.c:
13+
class: DemoApp\Method\MethodC
14+
tags:
15+
- { name: 'json_rpc_http_server.jsonrpc_method', method: 'bundledGetDummy' }
16+
jsonrpc.method.d:
17+
class: DemoApp\Method\MethodD
18+
tags:
19+
- { name: 'json_rpc_http_server.jsonrpc_method', method: 'bundledGetAnotherDummy' }
20+
21+
## Mapping aware service
22+
mapping_aware_service:
23+
public: true # In order to allow Behat context to load it later
24+
class: DemoApp\Collector\MappingCollector
25+
tags: ['json_rpc_http_server.method_aware']
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
<?php
2+
namespace DemoApp;
3+
4+
use Symfony\Component\Config\Loader\LoaderInterface;
5+
use Symfony\Component\DependencyInjection\ContainerBuilder;
6+
use Symfony\Component\Routing\RouteCollectionBuilder;
7+
8+
class KernelWithMappingCollectorListener extends AbstractKernel
9+
{
10+
public function registerBundles(): iterable
11+
{
12+
/** @noinspection PhpIncludeInspection */
13+
$contents = require $this->getProjectDir().'/'.$this->getConfigDirectory().'/bundles.php';
14+
foreach ($contents as $class => $envs) {
15+
if (isset($envs['all']) || isset($envs[$this->environment])) {
16+
yield new $class();
17+
}
18+
}
19+
}
20+
21+
/**
22+
* {@inheritdoc}
23+
*/
24+
protected function configureContainer(ContainerBuilder $container, LoaderInterface $loader)
25+
{
26+
$container->setParameter('container.dumper.inline_class_loader', true);
27+
$confDir = $this->getProjectDir().'/'.$this->getConfigDirectory();
28+
$loader->load($confDir.'/config'.self::CONFIG_EXTS, 'glob');
29+
$loader->load($confDir.'/services'.self::CONFIG_EXTS, 'glob');
30+
}
31+
32+
/**
33+
* {@inheritdoc}
34+
*/
35+
protected function configureRoutes(RouteCollectionBuilder $routes)
36+
{
37+
$confDir = $this->getProjectDir().'/'.$this->getConfigDirectory();
38+
$routes->import($confDir.'/routes'.self::CONFIG_EXTS, '/', 'glob');
39+
}
40+
41+
/**
42+
* {@inheritdoc}
43+
*/
44+
public function getConfigDirectory() : string
45+
{
46+
return 'mapping_collector_config';
47+
}
48+
}

features/mapping_collector.feature

+1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
Feature: Mapping collector
22

33
Scenario: Check that configured mapping aware service have methods mapping
4+
Given I will use kernel with MappingCollector listener
45
Then Collector should have "DemoApp\Method\MethodA" JSON-RPC method with name "bundledMethodA"
56
And Collector should have "DemoApp\Method\MethodA" JSON-RPC method with name "bundledMethodA"
67
And Collector should have "DemoApp\Method\MethodB" JSON-RPC method with name "bundledMethodB"

src/DependencyInjection/JsonRpcHttpServerExtension.php

-4
Original file line numberDiff line numberDiff line change
@@ -153,10 +153,6 @@ private function binJsonRpcMethods(ContainerBuilder $container) : void
153153
{
154154
$mappingAwareServiceDefinitionList = $this->findAndValidateMappingAwareDefinitionList($container);
155155

156-
if (0 === count($mappingAwareServiceDefinitionList)) {
157-
return;
158-
}
159-
160156
$jsonRpcMethodDefinitionList = (new JsonRpcMethodDefinitionHelper())
161157
->findAndValidateJsonRpcMethodDefinition($container);
162158

0 commit comments

Comments
 (0)