77use Soap \Encoding \Encoder \Context ;
88use Soap \Encoding \Encoder \ElementEncoder ;
99use Soap \Encoding \Encoder \Feature \ElementContextEnhancer ;
10+ use Soap \Encoding \Encoder \Feature \XsiTypeCalculator ;
1011use Soap \Encoding \Encoder \SimpleType \IntTypeEncoder ;
1112use Soap \Encoding \Encoder \SimpleType \StringTypeEncoder ;
1213use Soap \Encoding \Encoder \XmlEncoder ;
1314use Soap \Encoding \Xml \Node \Element ;
1415use Soap \Engine \Metadata \Model \TypeMeta ;
1516use Soap \Engine \Metadata \Model \XsdType ;
17+ use Soap \WsdlReader \Model \Definitions \BindingUse ;
1618use VeeWee \Reflecta \Iso \Iso ;
1719
1820#[CoversClass(ElementEncoder::class)]
@@ -25,7 +27,11 @@ public static function provideIsomorphicCases(): iterable
2527 'context ' => $ context = self ::createContext (
2628 $ xsdType = XsdType::guess ('string ' )
2729 ->withXmlTargetNodeName ('hello ' )
28- ->withMeta (static fn (TypeMeta $ meta ): TypeMeta => $ meta ->withIsQualified (true ))
30+ ->withMeta (
31+ static fn (TypeMeta $ meta ): TypeMeta => $ meta
32+ ->withIsQualified (true )
33+ ->withIsSimple (true )
34+ )
2935 ),
3036 ];
3137
@@ -79,6 +85,32 @@ public function enhanceElementContext(Context $context): Context
7985 'xml ' => '<bonjour>32</bonjour> ' ,
8086 'data ' => 32 ,
8187 ];
88+ yield 'xsi-type-calculating-encoder ' => [
89+ ...$ baseConfig ,
90+ 'encoder ' => $ encoder = new ElementEncoder (new class implements ElementContextEnhancer, XmlEncoder, XsiTypeCalculator {
91+ public function iso (Context $ context ): Iso
92+ {
93+ return (new IntTypeEncoder ())->iso ($ context );
94+ }
95+
96+ public function enhanceElementContext (Context $ context ): Context
97+ {
98+ return $ context ->withBindingUse (BindingUse::ENCODED );
99+ }
100+
101+ public function resolveXsiTypeForValue (Context $ context , mixed $ value ): string
102+ {
103+ return 'xsd: ' .get_debug_type ($ value );
104+ }
105+
106+ public function shouldIncludeXsiTargetNamespace (Context $ context ): bool
107+ {
108+ return true ;
109+ }
110+ }),
111+ 'xml ' => '<hello xmlns:xsd="http://www.w3.org/2001/XMLSchema" xsi:type="xsd:int" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">32</hello> ' ,
112+ 'data ' => 32 ,
113+ ];
82114 }
83115
84116 public function test_it_can_decode_from_xml_item (): void
0 commit comments