|
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\Decoder\JsonTypeDecoder; |
|
9
|
|
|
use Chubbyphp\Deserialization\Decoder\JsonxTypeDecoder; |
|
10
|
|
|
use Chubbyphp\Deserialization\Decoder\UrlEncodedTypeDecoder; |
|
11
|
|
|
use Chubbyphp\Deserialization\Decoder\XmlTypeDecoder; |
|
12
|
|
|
use Chubbyphp\Deserialization\Decoder\YamlTypeDecoder; |
|
13
|
|
|
use Chubbyphp\Deserialization\Denormalizer\Denormalizer; |
|
14
|
|
|
use Chubbyphp\Deserialization\Denormalizer\DenormalizerObjectMappingRegistry; |
|
15
|
|
|
use Chubbyphp\Deserialization\Deserializer; |
|
16
|
|
|
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface; |
|
17
|
|
|
use Symfony\Component\DependencyInjection\ContainerBuilder; |
|
18
|
|
|
use Symfony\Component\DependencyInjection\ContainerInterface; |
|
19
|
|
|
use Symfony\Component\DependencyInjection\Reference; |
|
20
|
|
|
use Symfony\Component\Yaml\Yaml; |
|
21
|
|
|
|
|
22
|
|
|
final class DeserializationCompilerPass implements CompilerPassInterface |
|
23
|
|
|
{ |
|
24
|
|
|
public function process(ContainerBuilder $container): void |
|
25
|
|
|
{ |
|
26
|
|
|
$container->register('chubbyphp.deserializer', Deserializer::class)->setPublic(true)->setArguments([ |
|
27
|
1 |
|
new Reference('chubbyphp.deserializer.decoder'), |
|
28
|
|
|
new Reference('chubbyphp.deserializer.denormalizer'), |
|
29
|
1 |
|
]); |
|
30
|
1 |
|
|
|
31
|
1 |
|
$container |
|
32
|
|
|
->register('chubbyphp.deserializer.decoder.type.json', JsonTypeDecoder::class) |
|
33
|
|
|
->addTag('chubbyphp.deserializer.decoder.type') |
|
34
|
|
|
; |
|
35
|
1 |
|
|
|
36
|
1 |
|
$container |
|
37
|
|
|
->register('chubbyphp.deserializer.decoder.type.jsonx', JsonxTypeDecoder::class) |
|
38
|
|
|
->addTag('chubbyphp.deserializer.decoder.type') |
|
39
|
|
|
; |
|
40
|
1 |
|
|
|
41
|
1 |
|
$container |
|
42
|
|
|
->register('chubbyphp.deserializer.decoder.type.urlencoded', UrlEncodedTypeDecoder::class) |
|
43
|
|
|
->addTag('chubbyphp.deserializer.decoder.type') |
|
44
|
|
|
; |
|
45
|
1 |
|
|
|
46
|
1 |
|
$container |
|
47
|
|
|
->register('chubbyphp.deserializer.decoder.type.xml', XmlTypeDecoder::class) |
|
48
|
|
|
->addTag('chubbyphp.deserializer.decoder.type') |
|
49
|
|
|
; |
|
50
|
1 |
|
|
|
51
|
1 |
|
if (class_exists(Yaml::class)) { |
|
52
|
|
|
$container |
|
53
|
|
|
->register('chubbyphp.deserializer.decoder.type.yml', YamlTypeDecoder::class) |
|
54
|
1 |
|
->addTag('chubbyphp.deserializer.decoder.type') |
|
55
|
|
|
; |
|
56
|
1 |
|
} |
|
57
|
1 |
|
|
|
58
|
|
|
$decoderTypeReferences = []; |
|
59
|
|
|
foreach ($container->findTaggedServiceIds('chubbyphp.deserializer.decoder.type') as $id => $tags) { |
|
60
|
|
|
$decoderTypeReferences[] = new Reference($id); |
|
61
|
1 |
|
} |
|
62
|
1 |
|
|
|
63
|
1 |
|
$container |
|
64
|
|
|
->register('chubbyphp.deserializer.decoder', Decoder::class) |
|
65
|
|
|
->setPublic(true) |
|
66
|
|
|
->setArguments([$decoderTypeReferences]) |
|
67
|
1 |
|
; |
|
68
|
1 |
|
|
|
69
|
1 |
|
$container |
|
70
|
|
|
->register('chubbyphp.deserializer.denormalizer', Denormalizer::class) |
|
71
|
|
|
->setPublic(true) |
|
72
|
|
|
->setArguments([ |
|
73
|
1 |
|
new Reference('chubbyphp.deserializer.denormalizer.objectmappingregistry'), |
|
74
|
1 |
|
new Reference('logger', ContainerInterface::IGNORE_ON_INVALID_REFERENCE), |
|
75
|
1 |
|
]) |
|
76
|
1 |
|
; |
|
77
|
1 |
|
|
|
78
|
|
|
$denormalizerObjectMappingReferences = []; |
|
79
|
|
|
foreach ($container->findTaggedServiceIds('chubbyphp.deserializer.denormalizer.objectmapping') as $id => $tags) { |
|
80
|
|
|
$denormalizerObjectMappingReferences[] = new Reference($id); |
|
81
|
1 |
|
} |
|
82
|
1 |
|
|
|
83
|
1 |
|
$container |
|
84
|
|
|
->register( |
|
85
|
|
|
'chubbyphp.deserializer.denormalizer.objectmappingregistry', |
|
86
|
|
|
DenormalizerObjectMappingRegistry::class |
|
87
|
1 |
|
) |
|
88
|
1 |
|
->setPublic(true) |
|
89
|
1 |
|
->setArguments([$denormalizerObjectMappingReferences]) |
|
90
|
|
|
; |
|
91
|
1 |
|
} |
|
92
|
|
|
} |
|
93
|
|
|
|