Skip to content

Commit 1860541

Browse files
committed
Added ability to encode arrays with "SOAP-ENC:Array" type instead of WSDL type. To activate the ability use "feature"=>SOAP_USE_XSI_ARRAY_TYPE option in SoapClient/SoapServer constructors.
1 parent 7e34938 commit 1860541

File tree

9 files changed

+147
-9
lines changed

9 files changed

+147
-9
lines changed

ext/soap/php_encoding.c

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1622,6 +1622,7 @@ static xmlNodePtr to_xml_object(encodeTypePtr type, zval *data, int style, xmlNo
16221622
xmlAddChild(parent, xmlParam);
16231623
if (style == SOAP_ENCODED) {
16241624
set_xsi_nil(xmlParam);
1625+
set_ns_and_type(xmlParam, type);
16251626
}
16261627
return xmlParam;
16271628
}
@@ -2016,7 +2017,17 @@ static xmlNodePtr to_xml_array(encodeTypePtr type, zval *data, int style, xmlNod
20162017
xmlParam = xmlNewNode(NULL, BAD_CAST("BOGUS"));
20172018
xmlAddChild(parent, xmlParam);
20182019

2019-
FIND_ZVAL_NULL(data, xmlParam, style);
2020+
if (!data || Z_TYPE_P(data) == IS_NULL) {
2021+
if (style == SOAP_ENCODED) {
2022+
set_xsi_nil(xmlParam);
2023+
if (SOAP_GLOBAL(features) & SOAP_USE_XSI_ARRAY_TYPE) {
2024+
set_ns_and_type_ex(xmlParam, (soap_version == SOAP_1_1) ? SOAP_1_1_ENC_NAMESPACE : SOAP_1_2_ENC_NAMESPACE, "Array");
2025+
} else {
2026+
set_ns_and_type(xmlParam, type);
2027+
}
2028+
}
2029+
return xmlParam;
2030+
}
20202031

20212032
if (Z_TYPE_P(data) == IS_ARRAY) {
20222033
sdlAttributePtr *arrayType;
@@ -2189,7 +2200,11 @@ static xmlNodePtr to_xml_array(encodeTypePtr type, zval *data, int style, xmlNod
21892200
efree(dims);
21902201
}
21912202
if (style == SOAP_ENCODED) {
2192-
set_ns_and_type(xmlParam, type);
2203+
if (SOAP_GLOBAL(features) & SOAP_USE_XSI_ARRAY_TYPE) {
2204+
set_ns_and_type_ex(xmlParam, (soap_version == SOAP_1_1) ? SOAP_1_1_ENC_NAMESPACE : SOAP_1_2_ENC_NAMESPACE, "Array");
2205+
} else {
2206+
set_ns_and_type(xmlParam, type);
2207+
}
21932208
}
21942209
return xmlParam;
21952210
}
@@ -3014,9 +3029,9 @@ xmlNodePtr sdl_guess_convert_xml(encodeTypePtr enc, zval *data, int style, xmlNo
30143029
if (type->encode &&
30153030
(type->encode->details.type == IS_ARRAY ||
30163031
type->encode->details.type == SOAP_ENC_ARRAY)) {
3017-
ret = to_xml_array(enc, data, style, parent);
3032+
return to_xml_array(enc, data, style, parent);
30183033
} else {
3019-
ret = to_xml_object(enc, data, style, parent);
3034+
return to_xml_object(enc, data, style, parent);
30203035
}
30213036
break;
30223037
default:

ext/soap/php_soap.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,8 @@ typedef struct _soap_client_object {
192192
#define SOAP_AUTHENTICATION_DIGEST 1
193193

194194
#define SOAP_SINGLE_ELEMENT_ARRAYS (1<<0)
195-
#define SOAP_WAIT_ONE_WAY_CALLS (2<<0)
195+
#define SOAP_WAIT_ONE_WAY_CALLS (1<<1)
196+
#define SOAP_USE_XSI_ARRAY_TYPE (1<<2)
196197

197198
#define WSDL_CACHE_NONE 0x0
198199
#define WSDL_CACHE_DISK 0x1

ext/soap/soap.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -862,6 +862,7 @@ PHP_MINIT_FUNCTION(soap)
862862

863863
REGISTER_LONG_CONSTANT("SOAP_SINGLE_ELEMENT_ARRAYS", SOAP_SINGLE_ELEMENT_ARRAYS, CONST_CS | CONST_PERSISTENT);
864864
REGISTER_LONG_CONSTANT("SOAP_WAIT_ONE_WAY_CALLS", SOAP_WAIT_ONE_WAY_CALLS, CONST_CS | CONST_PERSISTENT);
865+
REGISTER_LONG_CONSTANT("SOAP_USE_XSI_ARRAY_TYPE", SOAP_USE_XSI_ARRAY_TYPE, CONST_CS | CONST_PERSISTENT);
865866

866867
REGISTER_LONG_CONSTANT("WSDL_CACHE_NONE", WSDL_CACHE_NONE, CONST_CS | CONST_PERSISTENT);
867868
REGISTER_LONG_CONSTANT("WSDL_CACHE_DISK", WSDL_CACHE_DISK, CONST_CS | CONST_PERSISTENT);

ext/soap/tests/interop/Round2/Base/r2_base_009s.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ echo "ok\n";
1414
?>
1515
--EXPECT--
1616
<?xml version="1.0" encoding="UTF-8"?>
17-
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns1="http://soapinterop.org/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:ns2="http://soapinterop.org/xsd" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/" SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"><SOAP-ENV:Body><ns1:echoStringArray><inputStringArray xsi:nil="true" xsi:type="ns2:ArrayOfstring"/></ns1:echoStringArray></SOAP-ENV:Body></SOAP-ENV:Envelope>
17+
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns1="http://soapinterop.org/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/" xmlns:ns2="http://soapinterop.org/xsd" xmlns:xsd="http://www.w3.org/2001/XMLSchema" SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"><SOAP-ENV:Body><ns1:echoStringArray><inputStringArray xsi:nil="true" xsi:type="ns2:ArrayOfstring"/></ns1:echoStringArray></SOAP-ENV:Body></SOAP-ENV:Envelope>
1818
<?xml version="1.0" encoding="UTF-8"?>
1919
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns1="http://soapinterop.org/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:ns2="http://soapinterop.org/xsd" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/" SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"><SOAP-ENV:Body><ns1:echoStringArrayResponse><outputStringArray xsi:nil="true" xsi:type="ns2:ArrayOfstring"/></ns1:echoStringArrayResponse></SOAP-ENV:Body></SOAP-ENV:Envelope>
2020
ok

ext/soap/tests/schema/schema081.phpt

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
--TEST--
2+
SOAP XML Schema 81: SOAP 1.1 Array with SOAP_USE_XSI_ARRAY_TYPE
3+
--SKIPIF--
4+
<?php require_once('skipif.inc'); ?>
5+
--FILE--
6+
<?php
7+
include "test_schema.inc";
8+
$schema = <<<EOF
9+
<complexType name="testType">
10+
<complexContent>
11+
<restriction base="SOAP-ENC:Array">
12+
<attribute ref="SOAP-ENC:arrayType" wsdl:arrayType="int[]"/>
13+
</restriction>
14+
</complexContent>
15+
</complexType>
16+
EOF;
17+
test_schema($schema,'type="tns:testType"',array(123,123.5),"rpc","encoded",'',SOAP_USE_XSI_ARRAY_TYPE);
18+
echo "ok";
19+
?>
20+
--EXPECT--
21+
<?xml version="1.0" encoding="UTF-8"?>
22+
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns1="http://test-uri/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"><SOAP-ENV:Body><ns1:test><testParam SOAP-ENC:arrayType="xsd:int[2]" xsi:type="SOAP-ENC:Array"><item xsi:type="xsd:int">123</item><item xsi:type="xsd:int">123</item></testParam></ns1:test></SOAP-ENV:Body></SOAP-ENV:Envelope>
23+
array(2) {
24+
[0]=>
25+
int(123)
26+
[1]=>
27+
int(123)
28+
}
29+
ok

ext/soap/tests/schema/schema082.phpt

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
--TEST--
2+
SOAP XML Schema 82: SOAP 1.1 Array with SOAP_USE_XSI_ARRAY_TYPE (second way)
3+
--SKIPIF--
4+
<?php require_once('skipif.inc'); ?>
5+
--FILE--
6+
<?php
7+
include "test_schema.inc";
8+
$schema = <<<EOF
9+
<complexType name="testType">
10+
<complexContent>
11+
<restriction base="SOAP-ENC:Array">
12+
<all>
13+
<element name="x_item" type="int" maxOccurs="unbounded"/>
14+
</all>
15+
</restriction>
16+
</complexContent>
17+
</complexType>
18+
EOF;
19+
test_schema($schema,'type="tns:testType"',array(123,123.5),"rpc","encoded",'',SOAP_USE_XSI_ARRAY_TYPE);
20+
echo "ok";
21+
?>
22+
--EXPECT--
23+
<?xml version="1.0" encoding="UTF-8"?>
24+
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns1="http://test-uri/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"><SOAP-ENV:Body><ns1:test><testParam SOAP-ENC:arrayType="xsd:int[2]" xsi:type="SOAP-ENC:Array"><x_item xsi:type="xsd:int">123</x_item><x_item xsi:type="xsd:int">123</x_item></testParam></ns1:test></SOAP-ENV:Body></SOAP-ENV:Envelope>
25+
array(2) {
26+
[0]=>
27+
int(123)
28+
[1]=>
29+
int(123)
30+
}
31+
ok

ext/soap/tests/schema/schema083.phpt

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
--TEST--
2+
SOAP XML Schema 83: SOAP 1.2 Array with SOAP_USE_XSI_ARRAY_TYPE
3+
--SKIPIF--
4+
<?php require_once('skipif.inc'); ?>
5+
--FILE--
6+
<?php
7+
include "test_schema.inc";
8+
$schema = <<<EOF
9+
<complexType name="testType">
10+
<complexContent>
11+
<restriction base="enc12:Array" xmlns:enc12="http://www.w3.org/2003/05/soap-encoding">
12+
<attribute ref="enc12:itemType" wsdl:itemType="int"/>
13+
<attribute ref="enc12:arraySize" wsdl:arraySize="*"/>
14+
</restriction>
15+
</complexContent>
16+
</complexType>
17+
EOF;
18+
test_schema($schema,'type="tns:testType"',array(123,123.5),"rpc","encoded",'',SOAP_USE_XSI_ARRAY_TYPE);
19+
echo "ok";
20+
?>
21+
--EXPECT--
22+
<?xml version="1.0" encoding="UTF-8"?>
23+
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns1="http://test-uri/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"><SOAP-ENV:Body><ns1:test><testParam SOAP-ENC:arrayType="xsd:int[2]" xsi:type="SOAP-ENC:Array"><item xsi:type="xsd:int">123</item><item xsi:type="xsd:int">123</item></testParam></ns1:test></SOAP-ENV:Body></SOAP-ENV:Envelope>
24+
array(2) {
25+
[0]=>
26+
int(123)
27+
[1]=>
28+
int(123)
29+
}
30+
ok

ext/soap/tests/schema/schema084.phpt

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
--TEST--
2+
SOAP XML Schema 84: SOAP 1.2 Array with SOAP_USE_XSI_ARRAY_TYPE (second way)
3+
--SKIPIF--
4+
<?php require_once('skipif.inc'); ?>
5+
--FILE--
6+
<?php
7+
include "test_schema.inc";
8+
$schema = <<<EOF
9+
<complexType name="testType">
10+
<complexContent>
11+
<restriction base="enc12:Array" xmlns:enc12="http://www.w3.org/2003/05/soap-encoding">
12+
<all>
13+
<element name="x_item" type="int" maxOccurs="unbounded"/>
14+
</all>
15+
</restriction>
16+
</complexContent>
17+
</complexType>
18+
EOF;
19+
test_schema($schema,'type="tns:testType"',array(123,123.5),"rpc","encoded",'',SOAP_USE_XSI_ARRAY_TYPE);
20+
echo "ok";
21+
?>
22+
--EXPECT--
23+
<?xml version="1.0" encoding="UTF-8"?>
24+
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns1="http://test-uri/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"><SOAP-ENV:Body><ns1:test><testParam SOAP-ENC:arrayType="xsd:int[2]" xsi:type="SOAP-ENC:Array"><x_item xsi:type="xsd:int">123</x_item><x_item xsi:type="xsd:int">123</x_item></testParam></ns1:test></SOAP-ENV:Body></SOAP-ENV:Envelope>
25+
array(2) {
26+
[0]=>
27+
int(123)
28+
[1]=>
29+
int(123)
30+
}
31+
ok

ext/soap/tests/schema/test_schema.inc

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ function test($input) {
66
$val = $input;
77
}
88

9-
function test_schema($schema,$type,$param,$style="rpc",$use="encoded", $attributeFormDefault='') {
9+
function test_schema($schema,$type,$param,$style="rpc",$use="encoded", $attributeFormDefault='',$features=0) {
1010
global $HTTP_RAW_POST_DATA, $val;
1111
$wsdl = <<<EOF
1212
<definitions name="InteropTest"
@@ -55,8 +55,8 @@ EOF;
5555
@fwrite($f,$wsdl);
5656
fclose($f);
5757
ini_set("soap.wsdl_cache_enabled",0);
58-
$x = new SoapClient($fname, array("trace"=>1,"exceptions"=>0));
59-
$y = new SoapServer($fname);
58+
$x = new SoapClient($fname, array("trace"=>1,"exceptions"=>0,"features"=>$features));
59+
$y = new SoapServer($fname, array("features"=>$features));
6060
$y->addfunction("test");
6161
unlink($fname);
6262

0 commit comments

Comments
 (0)