|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
namespace Chubbyphp\Deserialization\Provider; |
|
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 Pimple\Container; |
|
17
|
|
|
use Pimple\ServiceProviderInterface; |
|
18
|
|
|
use Symfony\Component\Yaml\Yaml; |
|
19
|
|
|
|
|
20
|
|
|
final class DeserializationProvider implements ServiceProviderInterface |
|
21
|
|
|
{ |
|
22
|
|
|
public function register(Container $container): void |
|
23
|
|
|
{ |
|
24
|
|
|
$container['deserializer'] = function () use ($container) { |
|
25
|
|
|
return new Deserializer($container['deserializer.decoder'], $container['deserializer.denormalizer']); |
|
26
|
|
|
}; |
|
27
|
1 |
|
|
|
28
|
1 |
|
$container['deserializer.decoder'] = function () use ($container) { |
|
29
|
|
|
return new Decoder($container['deserializer.decodertypes']); |
|
30
|
|
|
}; |
|
31
|
1 |
|
|
|
32
|
1 |
|
$container['deserializer.decodertypes'] = function () { |
|
33
|
|
|
$decoderTypes = []; |
|
34
|
|
|
|
|
35
|
1 |
|
$decoderTypes[] = new JsonTypeDecoder(); |
|
36
|
1 |
|
$decoderTypes[] = new JsonxTypeDecoder(); |
|
37
|
|
|
$decoderTypes[] = new UrlEncodedTypeDecoder(); |
|
38
|
1 |
|
$decoderTypes[] = new XmlTypeDecoder(); |
|
|
|
|
|
|
39
|
1 |
|
|
|
40
|
1 |
|
if (class_exists(Yaml::class)) { |
|
41
|
1 |
|
$decoderTypes[] = new YamlTypeDecoder(); |
|
42
|
|
|
} |
|
43
|
1 |
|
|
|
44
|
1 |
|
@trigger_error( |
|
45
|
|
|
'Register the decoder types by yourself:' |
|
46
|
|
|
.' $container[\'deserializer.decodertypes\'] = function () { return [new JsonTypeDecoder()]; };', |
|
47
|
1 |
|
E_USER_DEPRECATED |
|
48
|
|
|
); |
|
49
|
|
|
|
|
50
|
2 |
|
return $decoderTypes; |
|
51
|
2 |
|
}; |
|
52
|
2 |
|
|
|
53
|
2 |
|
$container['deserializer.denormalizer'] = function () use ($container) { |
|
54
|
|
|
return new Denormalizer( |
|
55
|
|
|
$container['deserializer.denormalizer.objectmappingregistry'], |
|
56
|
|
|
$container['logger'] ?? null |
|
57
|
2 |
|
); |
|
58
|
2 |
|
}; |
|
59
|
|
|
|
|
60
|
|
|
$container['deserializer.denormalizer.objectmappingregistry'] = function () use ($container) { |
|
61
|
2 |
|
return new DenormalizerObjectMappingRegistry($container['deserializer.denormalizer.objectmappings']); |
|
62
|
2 |
|
}; |
|
63
|
|
|
|
|
64
|
2 |
|
$container['deserializer.denormalizer.objectmappings'] = function () { |
|
65
|
|
|
return []; |
|
66
|
|
|
}; |
|
67
|
|
|
} |
|
68
|
|
|
} |
|
69
|
|
|
|