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