xref: /PHP-8.2/ext/soap/tests/typemap003.phpt (revision 8ae4b560)
1--TEST--
2SOAP Typemap 3: SoapClient support for typemap's from_xml()
3--EXTENSIONS--
4soap
5simplexml
6--INI--
7soap.wsdl_cache_enabled=0
8--FILE--
9<?php
10class TestSoapClient extends SoapClient{
11  function __doRequest($request, $location, $action, $version, $one_way = 0): ?string {
12        return <<<EOF
13<?xml version="1.0" encoding="UTF-8"?>
14<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns1="http://schemas.nothing.com" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/" SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"><SOAP-ENV:Body>
15<ns1:dotest2Response><res xsi:type="ns1:book">
16  <a xsi:type="xsd:string">foo</a>
17  <b xsi:type="xsd:string">bar</b>
18</res>
19</ns1:dotest2Response></SOAP-ENV:Body></SOAP-ENV:Envelope>
20EOF;
21    }
22}
23
24class book{
25    public $a="a";
26    public $b="c";
27
28}
29
30function book_from_xml($xml) {
31    $sxe = simplexml_load_string($xml);
32    $obj = new book;
33    $obj->a = (string)$sxe->a;
34    $obj->b = (string)$sxe->b;
35    return $obj;
36}
37
38$options=Array(
39        'actor' =>'http://schemas.nothing.com',
40        'typemap' => array(array("type_ns"   => "http://schemas.nothing.com",
41                                 "type_name" => "book",
42                                 "from_xml"  => "book_from_xml"))
43        );
44
45$client = new TestSoapClient(__DIR__."/classmap.wsdl",$options);
46$ret = $client->dotest2("???");
47var_dump($ret);
48echo "ok\n";
49?>
50--EXPECTF--
51object(book)#%d (2) {
52  ["a"]=>
53  string(3) "foo"
54  ["b"]=>
55  string(3) "bar"
56}
57ok
58