88use Soap \Encoding \Encoder \Feature ;
99use Soap \Encoding \Encoder \OptionalElementEncoder ;
1010use Soap \Encoding \Encoder \XmlEncoder ;
11+ use Soap \Encoding \Encoder \XsiTypeEncoder ;
1112use Soap \Engine \Metadata \Model \XsdType ;
13+ use Soap \WsdlReader \Model \Definitions \BindingUse ;
1214use function Psl \Iter \any ;
1315
1416final class EncoderDetector
@@ -25,11 +27,22 @@ public static function default(): self
2527 * @return XmlEncoder<mixed, string|null>
2628 */
2729 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
2842 {
2943 $ type = $ context ->type ;
3044 $ meta = $ type ->getMeta ();
3145
32- $ encoder = $ this ->detectSimpleTypeEncoder ($ type , $ context );
3346 if (!$ encoder instanceof Feature \ListAware && $ this ->detectIsListType ($ type )) {
3447 $ encoder = new SimpleListEncoder ($ encoder );
3548 }
@@ -43,6 +56,10 @@ public function __invoke(Context $context): XmlEncoder
4356 $ encoder = new ElementEncoder ($ encoder );
4457 }
4558
59+ if (!$ encoder instanceof Feature \DisregardXsiInformation && $ context ->bindingUse === BindingUse::ENCODED ) {
60+ $ encoder = new XsiTypeEncoder ($ encoder );
61+ }
62+
4663 if ($ meta ->isNullable ()->unwrapOr (false ) && !$ encoder instanceof Feature \OptionalAware) {
4764 $ encoder = new OptionalElementEncoder ($ encoder );
4865 }
@@ -54,8 +71,9 @@ public function __invoke(Context $context): XmlEncoder
5471 /**
5572 * @return XmlEncoder<mixed, string>
5673 */
57- private function detectSimpleTypeEncoder (XsdType $ type , Context $ context ): XmlEncoder
74+ private function detectSimpleTypeEncoder (Context $ context ): XmlEncoder
5875 {
76+ $ type = $ context ->type ;
5977 $ meta = $ type ->getMeta ();
6078
6179 // Try to find a direct match:
0 commit comments