8
8
use Soap \Encoding \Encoder \Feature ;
9
9
use Soap \Encoding \Encoder \OptionalElementEncoder ;
10
10
use Soap \Encoding \Encoder \XmlEncoder ;
11
+ use Soap \Encoding \Encoder \XsiTypeEncoder ;
11
12
use Soap \Engine \Metadata \Model \XsdType ;
13
+ use Soap \WsdlReader \Model \Definitions \BindingUse ;
12
14
use function Psl \Iter \any ;
13
15
14
16
final class EncoderDetector
@@ -25,11 +27,22 @@ public static function default(): self
25
27
* @return XmlEncoder<mixed, string|null>
26
28
*/
27
29
public function __invoke (Context $ context ): XmlEncoder
30
+ {
31
+ return $ this ->enhanceEncoder (
32
+ $ context ,
33
+ $ this ->detectSimpleTypeEncoder ($ context )
34
+ );
35
+ }
36
+
37
+ /**
38
+ * @param XmlEncoder<mixed, string> $encoder
39
+ * @return XmlEncoder<mixed, string|null>
40
+ */
41
+ private function enhanceEncoder (Context $ context , XmlEncoder $ encoder ): XmlEncoder
28
42
{
29
43
$ type = $ context ->type ;
30
44
$ meta = $ type ->getMeta ();
31
45
32
- $ encoder = $ this ->detectSimpleTypeEncoder ($ type , $ context );
33
46
if (!$ encoder instanceof Feature \ListAware && $ this ->detectIsListType ($ type )) {
34
47
$ encoder = new SimpleListEncoder ($ encoder );
35
48
}
@@ -43,6 +56,10 @@ public function __invoke(Context $context): XmlEncoder
43
56
$ encoder = new ElementEncoder ($ encoder );
44
57
}
45
58
59
+ if (!$ encoder instanceof Feature \DisregardXsiInformation && $ context ->bindingUse === BindingUse::ENCODED ) {
60
+ $ encoder = new XsiTypeEncoder ($ encoder );
61
+ }
62
+
46
63
if ($ meta ->isNullable ()->unwrapOr (false ) && !$ encoder instanceof Feature \OptionalAware) {
47
64
$ encoder = new OptionalElementEncoder ($ encoder );
48
65
}
@@ -54,8 +71,9 @@ public function __invoke(Context $context): XmlEncoder
54
71
/**
55
72
* @return XmlEncoder<mixed, string>
56
73
*/
57
- private function detectSimpleTypeEncoder (XsdType $ type , Context $ context ): XmlEncoder
74
+ private function detectSimpleTypeEncoder (Context $ context ): XmlEncoder
58
75
{
76
+ $ type = $ context ->type ;
59
77
$ meta = $ type ->getMeta ();
60
78
61
79
// Try to find a direct match:
0 commit comments