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