1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Bankiru\Api\JsonRpc\DependencyInjection; |
4
|
|
|
|
5
|
|
|
use Bankiru\Api\JsonRpc\Adapters\JMS\Compiler\JmsDriverPass; |
6
|
|
|
use Bankiru\Api\JsonRpc\Adapters\JMS\Compiler\RelationHandlerHelper; |
7
|
|
|
use Bankiru\Api\Rpc\RpcEvents; |
8
|
|
|
use JMS\SerializerBundle\JMSSerializerBundle; |
9
|
|
|
use Symfony\Bundle\SecurityBundle\SecurityBundle; |
10
|
|
|
use Symfony\Component\Config\FileLocator; |
11
|
|
|
use Symfony\Component\DependencyInjection\ContainerBuilder; |
12
|
|
|
use Symfony\Component\DependencyInjection\Extension\Extension; |
13
|
|
|
use Symfony\Component\DependencyInjection\Loader\YamlFileLoader; |
14
|
|
|
|
15
|
|
|
final class BankiruJsonRpcServerExtension extends Extension |
16
|
|
|
{ |
17
|
|
|
/** {@inheritdoc} */ |
18
|
1 |
|
public function load(array $configs, ContainerBuilder $container) |
19
|
|
|
{ |
20
|
1 |
|
$loader = new YamlFileLoader($container, new FileLocator(__DIR__ . '/../Resources/config')); |
21
|
1 |
|
$loader->load('jsonrpc.yml'); |
22
|
|
|
|
23
|
1 |
|
$config = $this->processConfiguration(new Configuration(), $configs); |
24
|
|
|
|
25
|
1 |
|
$this->configureSecurity($container, $config); |
26
|
1 |
|
$this->configureBuiltinAdapter($container, $config); |
27
|
1 |
|
$this->configureJmsAdapter($container, $config); |
28
|
|
|
|
29
|
1 |
|
if (!empty($config['view_listener'])) { |
30
|
1 |
|
$container->getDefinition($config['view_listener']) |
31
|
1 |
|
->setPublic(true) |
32
|
1 |
|
->addTag( |
33
|
1 |
|
'kernel.event_listener', |
34
|
|
|
[ |
35
|
1 |
|
'event' => RpcEvents::VIEW, |
36
|
1 |
|
'method' => 'onPlainResponse', |
37
|
1 |
|
'priority' => -254, |
38
|
|
|
] |
39
|
1 |
|
); |
40
|
1 |
|
} |
41
|
1 |
|
} |
42
|
|
|
|
43
|
1 |
|
public function getAlias() |
44
|
|
|
{ |
45
|
1 |
|
return 'jsonrpc_server'; |
46
|
|
|
} |
47
|
|
|
|
48
|
|
|
/** |
49
|
|
|
* @param ContainerBuilder $container |
50
|
|
|
*/ |
51
|
1 |
|
private function configureBuiltinAdapter(ContainerBuilder $container, array $config) |
|
|
|
|
52
|
|
|
{ |
53
|
1 |
|
$loader = new YamlFileLoader($container, new FileLocator(__DIR__ . '/../Resources/config/adapters')); |
54
|
|
|
|
55
|
1 |
|
$loader->load('builtin.yml'); |
56
|
1 |
|
} |
57
|
|
|
|
58
|
|
|
/** |
59
|
|
|
* @param ContainerBuilder $container |
60
|
|
|
*/ |
61
|
1 |
|
private function configureJmsAdapter(ContainerBuilder $container, array $config) |
62
|
|
|
{ |
63
|
1 |
|
if (!in_array(JMSSerializerBundle::class, $container->getParameter('kernel.bundles'), true)) { |
64
|
|
|
return; |
65
|
|
|
} |
66
|
|
|
|
67
|
1 |
|
$loader = new YamlFileLoader($container, new FileLocator(__DIR__ . '/../Resources/config/adapters')); |
68
|
1 |
|
$loader->load('jms.yml'); |
69
|
|
|
|
70
|
1 |
|
foreach ($config['adapters']['jms']['relation_handlers'] as $handler => $emid) { |
71
|
1 |
|
RelationHandlerHelper::ConfigureRelationHandler($container, $handler, $emid); |
72
|
1 |
|
} |
73
|
1 |
|
} |
74
|
|
|
|
75
|
|
|
/** |
76
|
|
|
* @param ContainerBuilder $container |
77
|
|
|
*/ |
78
|
1 |
|
private function configureSecurity(ContainerBuilder $container, array $config) |
|
|
|
|
79
|
|
|
{ |
80
|
1 |
|
if (in_array(SecurityBundle::class, $container->getParameter('kernel.bundles'), true)) { |
81
|
1 |
|
$loader = new YamlFileLoader($container, new FileLocator(__DIR__ . '/../Resources/config')); |
82
|
1 |
|
$loader->load('security.yml'); |
83
|
1 |
|
} |
84
|
1 |
|
} |
85
|
|
|
} |
86
|
|
|
|
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.