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