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
|
1 |
|
public function process(ContainerBuilder $container) |
14
|
|
|
{ |
15
|
1 |
|
foreach ($container->getParameter('jsonrpc_server.handlers') as $handler => $emid) { |
16
|
1 |
|
$this->configureRelationHandler($container, $handler, $emid); |
17
|
1 |
|
} |
18
|
1 |
|
} |
19
|
|
|
|
20
|
1 |
|
private function configureRelationHandler(ContainerBuilder $builder, $handler, $emid) |
21
|
|
|
{ |
22
|
1 |
|
if (!$builder->has($emid)) { |
23
|
|
|
return; |
24
|
|
|
} |
25
|
|
|
|
26
|
1 |
|
$builder->register('jms_serializer.handler.relation.' . $handler, RelationsHandler::class) |
27
|
1 |
|
->setArguments([new Reference($emid)]) |
28
|
1 |
|
->addTag( |
29
|
1 |
|
'jms_serializer.handler', |
30
|
|
|
[ |
31
|
1 |
|
'type' => $handler, |
32
|
1 |
|
'direction' => 'serialization', |
33
|
1 |
|
'format' => 'json', |
34
|
1 |
|
'method' => 'serializeRelation', |
35
|
|
|
] |
36
|
1 |
|
) |
37
|
1 |
|
->addTag( |
38
|
1 |
|
'jms_serializer.handler', |
39
|
|
|
[ |
40
|
1 |
|
'type' => $handler, |
41
|
1 |
|
'direction' => 'deserialization', |
42
|
1 |
|
'format' => 'json', |
43
|
1 |
|
'method' => 'deserializeRelation', |
44
|
|
|
] |
45
|
1 |
|
) |
46
|
1 |
|
->addTag( |
47
|
1 |
|
'jms_serializer.handler', |
48
|
|
|
[ |
49
|
1 |
|
'type' => $handler . '<?>', |
50
|
1 |
|
'direction' => 'serialization', |
51
|
1 |
|
'format' => 'json', |
52
|
1 |
|
'method' => 'serializeRelation', |
53
|
|
|
] |
54
|
1 |
|
) |
55
|
1 |
|
->addTag( |
56
|
1 |
|
'jms_serializer.handler', |
57
|
|
|
[ |
58
|
1 |
|
'type' => $handler . '<?>', |
59
|
1 |
|
'direction' => 'deserialization', |
60
|
1 |
|
'format' => 'json', |
61
|
1 |
|
'method' => 'deserializeRelation', |
62
|
|
|
] |
63
|
1 |
|
); |
64
|
1 |
|
} |
65
|
|
|
} |
66
|
|
|
|