1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace Chubbyphp\Deserialization\DependencyInjection; |
6
|
|
|
|
7
|
|
|
use Chubbyphp\Deserialization\Decoder\Decoder; |
8
|
|
|
use Chubbyphp\Deserialization\Denormalizer\Denormalizer; |
9
|
|
|
use Chubbyphp\Deserialization\Denormalizer\DenormalizerObjectMappingRegistry; |
10
|
|
|
use Chubbyphp\Deserialization\Deserializer; |
11
|
|
|
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface; |
12
|
|
|
use Symfony\Component\DependencyInjection\ContainerBuilder; |
13
|
|
|
use Symfony\Component\DependencyInjection\Reference; |
14
|
|
|
use Symfony\Component\DependencyInjection\ContainerInterface; |
15
|
|
|
|
16
|
|
|
final class DeserializationCompilerPass implements CompilerPassInterface |
17
|
|
|
{ |
18
|
|
|
/** |
19
|
|
|
* @param ContainerBuilder $container |
20
|
|
|
*/ |
21
|
1 |
|
public function process(ContainerBuilder $container) |
22
|
|
|
{ |
23
|
1 |
|
$container->register('chubbyphp.deserializer', Deserializer::class)->setPublic(true)->setArguments([ |
24
|
1 |
|
new Reference('chubbyphp.deserializer.decoder'), |
25
|
1 |
|
new Reference('chubbyphp.deserializer.denormalizer'), |
26
|
|
|
]); |
27
|
|
|
|
28
|
1 |
|
$decoderTypeReferences = []; |
29
|
1 |
|
foreach ($container->findTaggedServiceIds('chubbyphp.deserializer.decoder.type') as $id => $tags) { |
30
|
1 |
|
$decoderTypeReferences[] = new Reference($id); |
31
|
|
|
} |
32
|
|
|
|
33
|
|
|
$container |
34
|
1 |
|
->register('chubbyphp.deserializer.decoder', Decoder::class) |
35
|
1 |
|
->setPublic(true) |
36
|
1 |
|
->setArguments([$decoderTypeReferences]); |
37
|
|
|
|
38
|
|
|
$container |
39
|
1 |
|
->register('chubbyphp.deserializer.denormalizer', Denormalizer::class) |
40
|
1 |
|
->setPublic(true) |
41
|
1 |
|
->setArguments([ |
42
|
1 |
|
new Reference('chubbyphp.deserializer.denormalizer.objectmappingregistry'), |
43
|
1 |
|
new Reference('logger', ContainerInterface::IGNORE_ON_INVALID_REFERENCE), |
44
|
|
|
]); |
45
|
|
|
|
46
|
1 |
|
$denormalizerObjectMappingReferences = []; |
47
|
1 |
|
foreach ($container->findTaggedServiceIds('deserializer.denormalizer.objectmapping') as $id => $tags) { |
48
|
1 |
|
$denormalizerObjectMappingReferences[] = new Reference($id); |
49
|
|
|
} |
50
|
|
|
|
51
|
|
|
$container |
52
|
1 |
|
->register( |
53
|
1 |
|
'chubbyphp.deserializer.denormalizer.objectmappingregistry', |
54
|
1 |
|
DenormalizerObjectMappingRegistry::class |
55
|
|
|
) |
56
|
1 |
|
->setPublic(true) |
57
|
1 |
|
->setArguments([$denormalizerObjectMappingReferences]); |
58
|
1 |
|
} |
59
|
|
|
} |
60
|
|
|
|