xref: /PHP-7.4/ext/soap/tests/typemap001.phpt (revision 26dfce7f)
1--TEST--
2SOAP typemap 1: SoapServer support for typemap's from_xml()
3--SKIPIF--
4<?php require_once('skipif.inc'); ?>
5<?php if (!extension_loaded('simplexml')) die("skip simplexml extension not available"); ?>
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		'actor'   =>'http://schemas.nothing.com',
50		'typemap' => array(array("type_ns"   => "http://schemas.nothing.com",
51		                         "type_name" => "book",
52		                         "from_xml"  => "book_from_xml"))
53		);
54
55$server = new SoapServer(__DIR__."/classmap.wsdl",$options);
56$server->setClass("test");
57$server->handle($HTTP_RAW_POST_DATA);
58echo "ok\n";
59?>
60--EXPECT--
61<?xml version="1.0" encoding="UTF-8"?>
62<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><res xsi:type="xsd:string">Object: book(foo,bar)</res></ns1:dotestResponse></SOAP-ENV:Body></SOAP-ENV:Envelope>
63ok
64