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