1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Bankiru\Api\JsonRpc\DependencyInjection; |
4
|
|
|
|
5
|
|
|
use Bankiru\Api\JsonRpc\Adapters\JMS\Compiler\RelationHandlerHelper; |
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
|
|
|
|
14
|
|
|
final class BankiruJsonRpcServerExtension extends Extension |
15
|
|
|
{ |
16
|
|
|
/** {@inheritdoc} */ |
17
|
1 |
|
public function load(array $configs, ContainerBuilder $container) |
18
|
|
|
{ |
19
|
1 |
|
$loader = new YamlFileLoader($container, new FileLocator(__DIR__ . '/../Resources/config')); |
20
|
1 |
|
$loader->load('jsonrpc.yml'); |
21
|
|
|
|
22
|
1 |
|
$config = $this->processConfiguration(new Configuration(), $configs); |
23
|
|
|
|
24
|
1 |
|
$this->configureSecurity($container); |
25
|
1 |
|
$this->configureBuiltinAdapter($container); |
26
|
1 |
|
$this->configureJmsAdapter($container, $config); |
27
|
|
|
|
28
|
1 |
|
if (!empty($config['view_listener'])) { |
29
|
1 |
|
$container->getDefinition($config['view_listener']) |
30
|
1 |
|
->setPublic(true) |
31
|
1 |
|
->addTag( |
32
|
1 |
|
'kernel.event_listener', |
33
|
|
|
[ |
34
|
1 |
|
'event' => RpcEvents::VIEW, |
35
|
1 |
|
'method' => 'onPlainResponse', |
36
|
1 |
|
'priority' => -254, |
37
|
|
|
] |
38
|
1 |
|
); |
39
|
1 |
|
} |
40
|
1 |
|
} |
41
|
|
|
|
42
|
1 |
|
public function getAlias() |
43
|
|
|
{ |
44
|
1 |
|
return 'jsonrpc_server'; |
45
|
|
|
} |
46
|
|
|
|
47
|
|
|
/** |
48
|
|
|
* @param ContainerBuilder $container |
49
|
|
|
*/ |
50
|
1 |
|
private function configureBuiltinAdapter(ContainerBuilder $container) |
51
|
|
|
{ |
52
|
1 |
|
$loader = new YamlFileLoader($container, new FileLocator(__DIR__ . '/../Resources/config/adapters')); |
53
|
|
|
|
54
|
1 |
|
$loader->load('builtin.yml'); |
55
|
1 |
|
} |
56
|
|
|
|
57
|
|
|
/** |
58
|
|
|
* @param ContainerBuilder $container |
59
|
|
|
* @param array $config |
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 ((array)$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) |
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
|
|
|
|