|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Bankiru\Api\JsonRpc\Adapters\JMS\Compiler; |
|
4
|
|
|
|
|
5
|
|
|
use Bankiru\Api\JsonRpc\Adapters\JMS\RelationsHandler; |
|
6
|
|
|
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface; |
|
7
|
|
|
use Symfony\Component\DependencyInjection\ContainerBuilder; |
|
8
|
|
|
use Symfony\Component\DependencyInjection\Reference; |
|
9
|
|
|
|
|
10
|
|
|
final class RelationHandlerPass implements CompilerPassInterface |
|
11
|
|
|
{ |
|
12
|
|
|
/** {@inheritdoc} */ |
|
13
|
|
|
public function process(ContainerBuilder $container) |
|
14
|
|
|
{ |
|
15
|
|
|
if (!$container->hasParameter('jsonrpc_server.jms.handlers')) { |
|
16
|
|
|
return; |
|
17
|
|
|
} |
|
18
|
|
|
|
|
19
|
|
|
foreach ($container->getParameter('jsonrpc_server.jms.handlers') as $handler => $emid) { |
|
20
|
|
|
$this->configureRelationHandler($container, $handler, $emid); |
|
21
|
|
|
} |
|
22
|
|
|
} |
|
23
|
|
|
|
|
24
|
|
|
private function configureRelationHandler(ContainerBuilder $builder, $handler, $emid) |
|
25
|
|
|
{ |
|
26
|
|
|
if (!$builder->has($emid)) { |
|
27
|
|
|
return; |
|
28
|
|
|
} |
|
29
|
|
|
|
|
30
|
|
|
$builder->register('jms_serializer.handler.relation.' . $handler, RelationsHandler::class) |
|
31
|
|
|
->setArguments([new Reference($emid)]) |
|
32
|
|
|
->addTag( |
|
33
|
|
|
'jms_serializer.handler', |
|
34
|
|
|
[ |
|
35
|
|
|
'type' => $handler, |
|
36
|
|
|
'direction' => 'serialization', |
|
37
|
|
|
'format' => 'json', |
|
38
|
|
|
'method' => 'serializeRelation', |
|
39
|
|
|
] |
|
40
|
|
|
) |
|
41
|
|
|
->addTag( |
|
42
|
|
|
'jms_serializer.handler', |
|
43
|
|
|
[ |
|
44
|
|
|
'type' => $handler, |
|
45
|
|
|
'direction' => 'deserialization', |
|
46
|
|
|
'format' => 'json', |
|
47
|
|
|
'method' => 'deserializeRelation', |
|
48
|
|
|
] |
|
49
|
|
|
) |
|
50
|
|
|
->addTag( |
|
51
|
|
|
'jms_serializer.handler', |
|
52
|
|
|
[ |
|
53
|
|
|
'type' => $handler . '<?>', |
|
54
|
|
|
'direction' => 'serialization', |
|
55
|
|
|
'format' => 'json', |
|
56
|
|
|
'method' => 'serializeRelation', |
|
57
|
|
|
] |
|
58
|
|
|
) |
|
59
|
|
|
->addTag( |
|
60
|
|
|
'jms_serializer.handler', |
|
61
|
|
|
[ |
|
62
|
|
|
'type' => $handler . '<?>', |
|
63
|
|
|
'direction' => 'deserialization', |
|
64
|
|
|
'format' => 'json', |
|
65
|
|
|
'method' => 'deserializeRelation', |
|
66
|
|
|
] |
|
67
|
|
|
); |
|
68
|
|
|
} |
|
69
|
|
|
} |
|
70
|
|
|
|