21
21
use Symfony \Component \Serializer \Mapping \ClassDiscriminatorResolverInterface ;
22
22
use Symfony \Component \Serializer \Mapping \Factory \ClassMetadataFactoryInterface ;
23
23
use Symfony \Component \Serializer \NameConverter \NameConverterInterface ;
24
+ use Symfony \Component \Serializer \Normalizer \DenormalizerInterface ;
25
+ use Symfony \Component \Serializer \Normalizer \NormalizerInterface ;
24
26
use Symfony \Component \Serializer \Normalizer \ObjectNormalizer ;
27
+ use Symfony \Component \Serializer \SerializerAwareInterface ;
28
+ use Symfony \Component \Serializer \SerializerInterface ;
25
29
26
30
/**
27
31
* Document denormalizer for Elasticsearch.
30
34
*
31
35
* @author Baptiste Meyer <[email protected] >
32
36
*/
33
- final class DocumentNormalizer extends ObjectNormalizer // @phpstan-ignore-line
37
+ final class DocumentNormalizer implements NormalizerInterface, DenormalizerInterface, SerializerAwareInterface
34
38
{
35
39
public const FORMAT = 'elasticsearch ' ;
36
40
37
- public function __construct (private readonly ResourceMetadataCollectionFactoryInterface $ resourceMetadataCollectionFactory , ClassMetadataFactoryInterface $ classMetadataFactory = null , NameConverterInterface $ nameConverter = null , PropertyAccessorInterface $ propertyAccessor = null , PropertyTypeExtractorInterface $ propertyTypeExtractor = null , ClassDiscriminatorResolverInterface $ classDiscriminatorResolver = null , callable $ objectClassResolver = null , array $ defaultContext = [])
38
- {
39
- parent ::__construct ($ classMetadataFactory , $ nameConverter , $ propertyAccessor , $ propertyTypeExtractor , $ classDiscriminatorResolver , $ objectClassResolver , $ defaultContext );
41
+ private readonly ObjectNormalizer $ decoratedNormalizer ;
42
+
43
+ public function __construct (
44
+ private readonly ResourceMetadataCollectionFactoryInterface $ resourceMetadataCollectionFactory ,
45
+ ClassMetadataFactoryInterface $ classMetadataFactory = null ,
46
+ private readonly ?NameConverterInterface $ nameConverter = null ,
47
+ PropertyAccessorInterface $ propertyAccessor = null ,
48
+ PropertyTypeExtractorInterface $ propertyTypeExtractor = null ,
49
+ ClassDiscriminatorResolverInterface $ classDiscriminatorResolver = null ,
50
+ callable $ objectClassResolver = null ,
51
+ array $ defaultContext = [],
52
+ ) {
53
+ $ this ->decoratedNormalizer = new ObjectNormalizer ($ classMetadataFactory , $ nameConverter , $ propertyAccessor , $ propertyTypeExtractor , $ classDiscriminatorResolver , $ objectClassResolver , $ defaultContext );
40
54
}
41
55
42
56
/**
43
57
* {@inheritdoc}
44
58
*/
45
59
public function supportsDenormalization (mixed $ data , string $ type , string $ format = null , array $ context = []): bool
46
60
{
47
- return self ::FORMAT === $ format && parent :: supportsDenormalization ($ data , $ type , $ format , $ context ); // @phpstan-ignore-line symfony bc-layer
61
+ return self ::FORMAT === $ format && $ this -> decoratedNormalizer -> supportsDenormalization ($ data , $ type , $ format , $ context ); // @phpstan-ignore-line symfony bc-layer
48
62
}
49
63
50
64
/**
@@ -56,7 +70,7 @@ public function denormalize(mixed $data, string $class, string $format = null, a
56
70
$ data = $ this ->populateIdentifier ($ data , $ class )['_source ' ];
57
71
}
58
72
59
- return parent :: denormalize ($ data , $ class , $ format , $ context );
73
+ return $ this -> decoratedNormalizer -> denormalize ($ data , $ class , $ format , $ context );
60
74
}
61
75
62
76
/**
@@ -103,4 +117,20 @@ private function populateIdentifier(array $data, string $class): array
103
117
104
118
return $ data ;
105
119
}
120
+
121
+ /**
122
+ * {@inheritdoc}
123
+ */
124
+ public function setSerializer (SerializerInterface $ serializer ): void
125
+ {
126
+ $ this ->decoratedNormalizer ->setSerializer ($ serializer );
127
+ }
128
+
129
+ /**
130
+ * {@inheritdoc}
131
+ */
132
+ public function getSupportedTypes (?string $ format ): array
133
+ {
134
+ return self ::FORMAT === $ format ? ['object ' => true ] : [];
135
+ }
106
136
}
0 commit comments