xref: /PHP-8.2/ext/soap/tests/typemap005.phpt (revision 7f2f0c00)
1--TEST--
2SOAP typemap 5: SoapServer support for typemap's from_xml() (without WSDL)
3--EXTENSIONS--
4soap
5simplexml
6--INI--
7soap.wsdl_cache_enabled=0
8--FILE--
9<?php
10$GLOBALS['HTTP_RAW_POST_DATA']="
11<env:Envelope xmlns:env=\"http://schemas.xmlsoap.org/soap/envelope/\"
12    xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"
13    xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\"
14    xmlns:enc=\"http://schemas.xmlsoap.org/soap/encoding/\"
15    xmlns:ns1=\"http://schemas.nothing.com\"
16>
17  <env:Body>
18 <ns1:dotest>
19  <book xsi:type=\"ns1:book\">
20    <a xsi:type=\"xsd:string\">foo</a>
21    <b xsi:type=\"xsd:string\">bar</b>
22</book>
23</ns1:dotest>
24 </env:Body>
25<env:Header/>
26</env:Envelope>";
27
28function book_from_xml($xml) {
29    $sxe = simplexml_load_string($xml);
30    $obj = new book;
31    $obj->a = (string)$sxe->a;
32    $obj->b = (string)$sxe->b;
33    return $obj;
34}
35
36class test{
37    function dotest($book){
38        $classname=get_class($book);
39        return "Object: ".$classname. "(".$book->a.",".$book->b.")";
40    }
41}
42
43class book{
44    public $a="a";
45    public $b="c";
46
47}
48$options=Array(
49        'uri'     => "http://schemas.nothing.com",
50        'actor'   => 'http://schemas.nothing.com',
51        'typemap' => array(array("type_ns"   => "http://schemas.nothing.com",
52                                 "type_name" => "book",
53                                 "from_xml"  => "book_from_xml"))
54        );
55
56$server = new SoapServer(NULL,$options);
57$server->setClass("test");
58$server->handle($HTTP_RAW_POST_DATA);
59echo "ok\n";
60?>
61--EXPECT--
62<?xml version="1.0" encoding="UTF-8"?>
63<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><ns1:dotestResponse><return xsi:type="xsd:string">Object: book(foo,bar)</return></ns1:dotestResponse></SOAP-ENV:Body></SOAP-ENV:Envelope>
64ok
65