Fixed bug #36575 (SOAP: Incorrect complex type instantiation with hierarchies)

This commit is contained in:
Dmitry Stogov 2006-03-03 09:20:51 +00:00
parent b86007f0e1
commit 1facee1b94
7 changed files with 210 additions and 28 deletions

View File

@ -246,6 +246,23 @@ void whiteSpace_collapse(char* str)
*pos = '\0';
}
static encodePtr find_encoder_by_type_name(sdlPtr sdl, const char *type)
{
if (sdl && sdl->encoders) {
HashPosition pos;
encodePtr *enc;
for (zend_hash_internal_pointer_reset_ex(sdl->encoders, &pos);
zend_hash_get_current_data_ex(sdl->encoders, (void **) &enc, &pos) == SUCCESS;
zend_hash_move_forward_ex(sdl->encoders, &pos)) {
if (strcmp((*enc)->details.type_str, type) == 0) {
return *enc;
}
}
}
return NULL;
}
xmlNodePtr master_to_xml(encodePtr encode, zval *data, int style, xmlNodePtr parent)
{
xmlNodePtr node = NULL;
@ -329,7 +346,12 @@ xmlNodePtr master_to_xml(encodePtr encode, zval *data, int style, xmlNodePtr par
encodePtr enc = get_encoder(SOAP_GLOBAL(sdl), SOAP_GLOBAL(sdl)->target_ns, type_name);
if (enc) {
encode = enc;
}
} else if (SOAP_GLOBAL(sdl)) {
enc = find_encoder_by_type_name(SOAP_GLOBAL(sdl), type_name);
if (enc) {
encode = enc;
}
}
break;
}
}
@ -1202,7 +1224,7 @@ static void model_to_zval_object(zval *ret, sdlContentModelPtr model, xmlNodePtr
}
/* Struct encode/decode */
static zval *to_zval_object(encodeTypePtr type, xmlNodePtr data)
static zval *to_zval_object_ex(encodeTypePtr type, xmlNodePtr data, zend_class_entry *pce)
{
zval *ret;
xmlNodePtr trav;
@ -1213,7 +1235,9 @@ static zval *to_zval_object(encodeTypePtr type, xmlNodePtr data)
TSRMLS_FETCH();
ce = ZEND_STANDARD_CLASS_DEF_PTR;
if (SOAP_GLOBAL(class_map) && type->type_str) {
if (pce) {
ce = pce;
} else if (SOAP_GLOBAL(class_map) && type->type_str) {
zval **classname;
zend_class_entry *tmp;
@ -1256,7 +1280,20 @@ static zval *to_zval_object(encodeTypePtr type, xmlNodePtr data)
sdlType->encode->details.sdl_type->kind != XSD_TYPEKIND_SIMPLE &&
sdlType->encode->details.sdl_type->kind != XSD_TYPEKIND_LIST &&
sdlType->encode->details.sdl_type->kind != XSD_TYPEKIND_UNION) {
ret = master_to_zval_int(sdlType->encode, data);
if (ce != ZEND_STANDARD_CLASS_DEF_PTR &&
sdlType->encode->to_zval == sdl_guess_convert_zval &&
sdlType->encode->details.sdl_type != NULL &&
(sdlType->encode->details.sdl_type->kind == XSD_TYPEKIND_COMPLEX ||
sdlType->encode->details.sdl_type->kind == XSD_TYPEKIND_RESTRICTION ||
sdlType->encode->details.sdl_type->kind == XSD_TYPEKIND_EXTENSION) &&
(sdlType->encode->details.sdl_type->encode == NULL ||
(sdlType->encode->details.sdl_type->encode->details.type != IS_ARRAY &&
sdlType->encode->details.sdl_type->encode->details.type != SOAP_ENC_ARRAY))) {
ret = to_zval_object_ex(&sdlType->encode->details, data, ce);
} else {
ret = master_to_zval_int(sdlType->encode, data);
}
FIND_XML_NULL(data, ret);
if (get_zval_property(ret, "any" TSRMLS_CC) != NULL) {
unset_zval_property(ret, "any" TSRMLS_CC);
@ -1361,6 +1398,11 @@ static zval *to_zval_object(encodeTypePtr type, xmlNodePtr data)
return ret;
}
static zval *to_zval_object(encodeTypePtr type, xmlNodePtr data)
{
return to_zval_object_ex(type, data, NULL);
}
static int model_to_xml_object(xmlNodePtr node, sdlContentModelPtr model, zval *object, int style, int strict TSRMLS_DC)
{
switch (model->kind) {

View File

@ -2197,6 +2197,7 @@ PHP_METHOD(SoapClient, SoapClient)
MAKE_STD_ZVAL(class_map);
*class_map = **tmp;
INIT_PZVAL(class_map);
zval_copy_ctor(class_map);
#ifdef ZEND_ENGINE_2
class_map->refcount--;

View File

@ -49,7 +49,7 @@ class LogOffEvent {
public $audienceMemberId;
public $timestamp;
public $smokeStatus;
public $callInititator;
public $callInitiator;
function __construct($audienceMemberId, $timestamp, $smokeStatus) {
$this->audienceMemberId = $audienceMemberId;
@ -98,6 +98,15 @@ object(IVREvents)#%d (6) {
int(101)
["messageId"]=>
int(12345)
["source"]=>
string(3) "IVR"
["logOnEvent"]=>
object(LogOnEvent)#%d (2) {
["audienceMemberId"]=>
int(34567)
["timestamp"]=>
string(25) "2005-11-08T11:22:07+03:00"
}
["logOffEvent"]=>
array(2) {
[0]=>
@ -123,13 +132,4 @@ object(IVREvents)#%d (6) {
string(3) "IVR"
}
}
["logOnEvent"]=>
object(LogOnEvent)#%d (2) {
["audienceMemberId"]=>
int(34567)
["timestamp"]=>
string(25) "2005-11-08T11:22:07+03:00"
}
["source"]=>
string(3) "IVR"
}

View File

@ -50,7 +50,7 @@ class LogOffEvent {
public $audienceMemberId;
public $timestamp;
public $smokeStatus;
public $callInititator;
public $callInitiator;
function __construct($audienceMemberId, $timestamp, $smokeStatus) {
$this->audienceMemberId = $audienceMemberId;
@ -99,6 +99,18 @@ object(IVREvents)#%d (6) {
int(101)
["messageId"]=>
int(12345)
["source"]=>
string(3) "IVR"
["logOnEvent"]=>
array(1) {
[0]=>
object(LogOnEvent)#10 (2) {
["audienceMemberId"]=>
int(34567)
["timestamp"]=>
string(25) "2005-11-08T11:22:07+03:00"
}
}
["logOffEvent"]=>
array(2) {
[0]=>
@ -124,16 +136,4 @@ object(IVREvents)#%d (6) {
string(3) "IVR"
}
}
["logOnEvent"]=>
array(1) {
[0]=>
object(LogOnEvent)#10 (2) {
["audienceMemberId"]=>
int(34567)
["timestamp"]=>
string(25) "2005-11-08T11:22:07+03:00"
}
}
["source"]=>
string(3) "IVR"
}

View File

@ -0,0 +1,52 @@
--TEST--
Bug #36575 (Incorrect complex type instantiation with hierarchies)
--SKIPIF--
<?php require_once('skipif.inc'); ?>
--INI--
soap.wsdl_cache_enabled=0
--FILE--
<?php
abstract class CT_A1 {
public $var1;
}
class CT_A2 extends CT_A1 {
public $var2;
}
class CT_A3 extends CT_A2 {
public $var3;
}
// returns A2 in WSDL
function test( $a1 ) {
$a3 = new CT_A3();
$a3->var1 = $a1->var1;
$a3->var2 = "var two";
$a3->var3 = "var three";
return $a3;
}
$classMap = array("A1" => "CT_A1", "A2" => "CT_A2", "A3" => "CT_A3");
$client = new SoapClient(dirname(__FILE__)."/bug36575.wsdl", array("trace" => 1, "exceptions" => 0, "classmap" => $classMap));
$a2 = new CT_A2();
$a2->var1 = "one";
$a2->var2 = "two";
$client->test($a2);
$soapRequest = $client->__getLastRequest();
echo $soapRequest;
$server = new SoapServer(dirname(__FILE__)."/bug36575.wsdl", array("classmap" => $classMap));
$server->addFunction("test");
$server->handle($soapRequest);
echo "ok\n";
?>
--EXPECT--
<?xml version="1.0" encoding="UTF-8"?>
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns1="urn:test.soap#" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:ns2="urn:test.soap.types#" 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:test><a1 xsi:type="ns2:A2"><var1 xsi:type="xsd:string">one</var1><var2 xsi:type="xsd:string">two</var2></a1></ns1:test></SOAP-ENV:Body></SOAP-ENV:Envelope>
<?xml version="1.0" encoding="UTF-8"?>
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns1="urn:test.soap#" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:ns2="urn:test.soap.types#" 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:testResponse><result xsi:type="ns2:A3"><var1 xsi:type="xsd:string">one</var1><var2 xsi:type="xsd:string">var two</var2><var3 xsi:type="xsd:string">var three</var3></result></ns1:testResponse></SOAP-ENV:Body></SOAP-ENV:Envelope>
ok

View File

@ -0,0 +1,87 @@
<?xml version="1.0" encoding="utf-8"?>
<definitions name="shoppingcart"
xmlns="http://schemas.xmlsoap.org/wsdl/"
xmlns:tns="urn:test.soap#" targetNamespace="urn:test.soap#"
xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"
xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"
xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:types="urn:test.soap.types#">
<!-- all datatypes will be imported to namespace types: -->
<types>
<xs:schema
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:soap = "http://schemas.xmlsoap.org/wsdl/soap/"
xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"
xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/"
xmlns:tns="urn:test.soap.types#"
targetNamespace="urn:test.soap.types#">
<xs:complexType name="A1">
<xs:all>
<xs:element name="var1" type="xs:string" nillable="true"/>
</xs:all>
</xs:complexType>
<xs:complexType name="A2">
<xs:complexContent>
<xs:extension base="tns:A1">
<xs:all>
<xs:element name="var2" type="xs:string" nillable="true"/>
</xs:all>
</xs:extension>
</xs:complexContent>
</xs:complexType>
<xs:complexType name="A3">
<xs:complexContent>
<xs:extension base="tns:A2">
<xs:all>
<xs:element name="var3" type="xs:string" nillable="true"/>
</xs:all>
</xs:extension>
</xs:complexContent>
</xs:complexType>
</xs:schema>
</types>
<message name="test-request">
<part name="a1" type="types:A1"/>
</message>
<message name="test-response">
<part name="result" type="types:A2"/>
</message>
<portType name="catalog-porttype">
<operation name="test" parameterOrder="a1">
<input name="test-request" message="tns:test-request"/>
<output name="test-response" message="tns:test-response"/>
</operation>
</portType>
<!-- @type doesn't like tns: -->
<binding name="catalog-binding" type="tns:catalog-porttype">
<soap:binding style="rpc"
transport="http://schemas.xmlsoap.org/soap/http"/>
<operation name="test">
<soap:operation soapAction="urn:test.soap#test"/>
<input>
<soap:body use="encoded" namespace="urn:test.soap#"
encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"/>
</input>
<output>
<soap:body use="encoded" namespace="urn:test.soap#"
encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"/>
</output>
</operation>
</binding>
<service name="catalog">
<!-- @binding doesn't like to be tns: -->
<port name="catalog-port" binding="tns:catalog-binding">
<soap:address location="xxxxxxxx"/>
</port>
</service>
</definitions>

View File

@ -49,6 +49,6 @@ print_r($client->f());
--EXPECT--
B Object
(
[x] => 5
[y] => 6
[x] => 5
)