From: Dmitry Stogov Date: Tue, 20 Mar 2007 09:52:14 +0000 (+0000) Subject: Added ability to encode arrays with "SOAP-ENC:Array" type instead of WSDL type. To... X-Git-Tag: php-5.2.2RC1~119 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=3ee54ce92464994cb39f45924a75bc5f31992f49;p=php 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. --- diff --git a/NEWS b/NEWS index 3165bd1a4e..101d55e2e9 100644 --- a/NEWS +++ b/NEWS @@ -14,6 +14,10 @@ PHP NEWS - Improved SPL (Marcus) . Added SplFileInfo::getBasename(), DirectoryIterator::getBasename(). . Added SplFileInfo::getLinkTarget(), SplFileInfo::getRealPath(). +- Improved SOAP + . 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. (Rob, Dmitry) - Added --ri switch to CLI which allows to check extension information. (Marcus) - Added tidyNode::getParent() method (John, Nuno) - Added openbasedir and safemode checks in zip:// stream wrapper and diff --git a/ext/soap/php_encoding.c b/ext/soap/php_encoding.c index 83dd51c645..beeb99a38d 100644 --- a/ext/soap/php_encoding.c +++ b/ext/soap/php_encoding.c @@ -1655,6 +1655,7 @@ static xmlNodePtr to_xml_object(encodeTypePtr type, zval *data, int style, xmlNo xmlAddChild(parent, xmlParam); if (style == SOAP_ENCODED) { set_xsi_nil(xmlParam); + set_ns_and_type(xmlParam, type); } return xmlParam; } @@ -2047,7 +2048,17 @@ static xmlNodePtr to_xml_array(encodeTypePtr type, zval *data, int style, xmlNod xmlParam = xmlNewNode(NULL, BAD_CAST("BOGUS")); xmlAddChild(parent, xmlParam); - FIND_ZVAL_NULL(data, xmlParam, style); + if (!data || Z_TYPE_P(data) == IS_NULL) { + if (style == SOAP_ENCODED) { + set_xsi_nil(xmlParam); + if (SOAP_GLOBAL(features) & SOAP_USE_XSI_ARRAY_TYPE) { + set_ns_and_type_ex(xmlParam, (soap_version == SOAP_1_1) ? SOAP_1_1_ENC_NAMESPACE : SOAP_1_2_ENC_NAMESPACE, "Array"); + } else { + set_ns_and_type(xmlParam, type); + } + } + return xmlParam; + } if (Z_TYPE_P(data) == IS_ARRAY) { sdlAttributePtr *arrayType; @@ -2220,7 +2231,11 @@ static xmlNodePtr to_xml_array(encodeTypePtr type, zval *data, int style, xmlNod efree(dims); } if (style == SOAP_ENCODED) { - set_ns_and_type(xmlParam, type); + if (SOAP_GLOBAL(features) & SOAP_USE_XSI_ARRAY_TYPE) { + set_ns_and_type_ex(xmlParam, (soap_version == SOAP_1_1) ? SOAP_1_1_ENC_NAMESPACE : SOAP_1_2_ENC_NAMESPACE, "Array"); + } else { + set_ns_and_type(xmlParam, type); + } } return xmlParam; } @@ -3026,9 +3041,9 @@ xmlNodePtr sdl_guess_convert_xml(encodeTypePtr enc, zval *data, int style, xmlNo if (type->encode && (type->encode->details.type == IS_ARRAY || type->encode->details.type == SOAP_ENC_ARRAY)) { - ret = to_xml_array(enc, data, style, parent); + return to_xml_array(enc, data, style, parent); } else { - ret = to_xml_object(enc, data, style, parent); + return to_xml_object(enc, data, style, parent); } break; default: diff --git a/ext/soap/php_soap.h b/ext/soap/php_soap.h index e604e37541..b2da6ff35d 100644 --- a/ext/soap/php_soap.h +++ b/ext/soap/php_soap.h @@ -140,7 +140,8 @@ struct _soapService { #define SOAP_AUTHENTICATION_DIGEST 1 #define SOAP_SINGLE_ELEMENT_ARRAYS (1<<0) -#define SOAP_WAIT_ONE_WAY_CALLS (2<<0) +#define SOAP_WAIT_ONE_WAY_CALLS (1<<1) +#define SOAP_USE_XSI_ARRAY_TYPE (1<<2) #define WSDL_CACHE_NONE 0x0 #define WSDL_CACHE_DISK 0x1 diff --git a/ext/soap/soap.c b/ext/soap/soap.c index d7320be0f7..9cae584e81 100644 --- a/ext/soap/soap.c +++ b/ext/soap/soap.c @@ -663,6 +663,7 @@ PHP_MINIT_FUNCTION(soap) REGISTER_LONG_CONSTANT("SOAP_SINGLE_ELEMENT_ARRAYS", SOAP_SINGLE_ELEMENT_ARRAYS, CONST_CS | CONST_PERSISTENT); REGISTER_LONG_CONSTANT("SOAP_WAIT_ONE_WAY_CALLS", SOAP_WAIT_ONE_WAY_CALLS, CONST_CS | CONST_PERSISTENT); + REGISTER_LONG_CONSTANT("SOAP_USE_XSI_ARRAY_TYPE", SOAP_USE_XSI_ARRAY_TYPE, CONST_CS | CONST_PERSISTENT); REGISTER_LONG_CONSTANT("WSDL_CACHE_NONE", WSDL_CACHE_NONE, CONST_CS | CONST_PERSISTENT); REGISTER_LONG_CONSTANT("WSDL_CACHE_DISK", WSDL_CACHE_DISK, CONST_CS | CONST_PERSISTENT); diff --git a/ext/soap/tests/interop/Round2/Base/r2_base_009s.phpt b/ext/soap/tests/interop/Round2/Base/r2_base_009s.phpt index 071d54dc54..6aec611fb8 100644 --- a/ext/soap/tests/interop/Round2/Base/r2_base_009s.phpt +++ b/ext/soap/tests/interop/Round2/Base/r2_base_009s.phpt @@ -14,7 +14,7 @@ echo "ok\n"; ?> --EXPECT-- - + ok diff --git a/ext/soap/tests/schema/schema081.phpt b/ext/soap/tests/schema/schema081.phpt new file mode 100644 index 0000000000..337f081261 --- /dev/null +++ b/ext/soap/tests/schema/schema081.phpt @@ -0,0 +1,29 @@ +--TEST-- +SOAP XML Schema 81: SOAP 1.1 Array with SOAP_USE_XSI_ARRAY_TYPE +--SKIPIF-- + +--FILE-- + + + + + + + +EOF; +test_schema($schema,'type="tns:testType"',array(123,123.5),"rpc","encoded",'',SOAP_USE_XSI_ARRAY_TYPE); +echo "ok"; +?> +--EXPECT-- + +123123 +array(2) { + [0]=> + int(123) + [1]=> + int(123) +} +ok diff --git a/ext/soap/tests/schema/schema082.phpt b/ext/soap/tests/schema/schema082.phpt new file mode 100755 index 0000000000..34c4c76c25 --- /dev/null +++ b/ext/soap/tests/schema/schema082.phpt @@ -0,0 +1,31 @@ +--TEST-- +SOAP XML Schema 82: SOAP 1.1 Array with SOAP_USE_XSI_ARRAY_TYPE (second way) +--SKIPIF-- + +--FILE-- + + + + + + + + + +EOF; +test_schema($schema,'type="tns:testType"',array(123,123.5),"rpc","encoded",'',SOAP_USE_XSI_ARRAY_TYPE); +echo "ok"; +?> +--EXPECT-- + +123123 +array(2) { + [0]=> + int(123) + [1]=> + int(123) +} +ok diff --git a/ext/soap/tests/schema/schema083.phpt b/ext/soap/tests/schema/schema083.phpt new file mode 100755 index 0000000000..854c4f9ff6 --- /dev/null +++ b/ext/soap/tests/schema/schema083.phpt @@ -0,0 +1,30 @@ +--TEST-- +SOAP XML Schema 83: SOAP 1.2 Array with SOAP_USE_XSI_ARRAY_TYPE +--SKIPIF-- + +--FILE-- + + + + + + + + +EOF; +test_schema($schema,'type="tns:testType"',array(123,123.5),"rpc","encoded",'',SOAP_USE_XSI_ARRAY_TYPE); +echo "ok"; +?> +--EXPECT-- + +123123 +array(2) { + [0]=> + int(123) + [1]=> + int(123) +} +ok diff --git a/ext/soap/tests/schema/schema084.phpt b/ext/soap/tests/schema/schema084.phpt new file mode 100755 index 0000000000..94a9551faf --- /dev/null +++ b/ext/soap/tests/schema/schema084.phpt @@ -0,0 +1,31 @@ +--TEST-- +SOAP XML Schema 84: SOAP 1.2 Array with SOAP_USE_XSI_ARRAY_TYPE (second way) +--SKIPIF-- + +--FILE-- + + + + + + + + + +EOF; +test_schema($schema,'type="tns:testType"',array(123,123.5),"rpc","encoded",'',SOAP_USE_XSI_ARRAY_TYPE); +echo "ok"; +?> +--EXPECT-- + +123123 +array(2) { + [0]=> + int(123) + [1]=> + int(123) +} +ok diff --git a/ext/soap/tests/schema/test_schema.inc b/ext/soap/tests/schema/test_schema.inc index e1d4eeb508..a047f38b52 100644 --- a/ext/soap/tests/schema/test_schema.inc +++ b/ext/soap/tests/schema/test_schema.inc @@ -6,7 +6,7 @@ function test($input) { $val = $input; } -function test_schema($schema,$type,$param,$style="rpc",$use="encoded", $attributeFormDefault='') { +function test_schema($schema,$type,$param,$style="rpc",$use="encoded", $attributeFormDefault='',$features=0) { global $HTTP_RAW_POST_DATA, $val; $wsdl = <<1,"exceptions"=>0)); - $y = new SoapServer($fname); + $x = new SoapClient($fname, array("trace"=>1,"exceptions"=>0,"features"=>$features)); + $y = new SoapServer($fname, array("features"=>$features)); $y->addfunction("test"); unlink($fname);