]> granicus.if.org Git - php/commitdiff
Added ability to encode arrays with "SOAP-ENC:Array" type instead of WSDL type. To...
authorDmitry Stogov <dmitry@php.net>
Tue, 20 Mar 2007 09:52:33 +0000 (09:52 +0000)
committerDmitry Stogov <dmitry@php.net>
Tue, 20 Mar 2007 09:52:33 +0000 (09:52 +0000)
ext/soap/php_encoding.c
ext/soap/php_soap.h
ext/soap/soap.c
ext/soap/tests/interop/Round2/Base/r2_base_009s.phpt
ext/soap/tests/schema/schema081.phpt [new file with mode: 0644]
ext/soap/tests/schema/schema082.phpt [new file with mode: 0755]
ext/soap/tests/schema/schema083.phpt [new file with mode: 0755]
ext/soap/tests/schema/schema084.phpt [new file with mode: 0755]
ext/soap/tests/schema/test_schema.inc

index 6e4b16ac7cc57325fcf1a0fee328ff84014a3415..0e53d27848b4ce13fa5d6565f8a4baf58cd0baee 100644 (file)
@@ -1622,6 +1622,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;
        }
@@ -2016,7 +2017,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;
@@ -2189,7 +2200,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;
 }
@@ -3014,9 +3029,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:
index 1d883bd2c05da360321c690998f7eaaf5a879d19..e84f9820e868adc70f9033691f4db00719409403 100644 (file)
@@ -192,7 +192,8 @@ typedef struct _soap_client_object {
 #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
index 09332e0d5f7bcb87471b298b7c0f26dc7db74994..beea0179c645cf70cf52b5533fd6d12e572e4cff 100644 (file)
@@ -862,6 +862,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);
index 071d54dc54337a5301ff8902ec00f9dd66459e42..6aec611fb8da69b4ec9187aa53d0d350405ce21a 100644 (file)
@@ -14,7 +14,7 @@ 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="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>
+<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>
 <?xml version="1.0" encoding="UTF-8"?>
 <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>
 ok
diff --git a/ext/soap/tests/schema/schema081.phpt b/ext/soap/tests/schema/schema081.phpt
new file mode 100644 (file)
index 0000000..337f081
--- /dev/null
@@ -0,0 +1,29 @@
+--TEST--
+SOAP XML Schema 81: SOAP 1.1 Array with SOAP_USE_XSI_ARRAY_TYPE
+--SKIPIF--
+<?php require_once('skipif.inc'); ?>
+--FILE--
+<?php
+include "test_schema.inc";
+$schema = <<<EOF
+       <complexType name="testType">
+               <complexContent>
+                       <restriction base="SOAP-ENC:Array">
+           <attribute ref="SOAP-ENC:arrayType" wsdl:arrayType="int[]"/>
+       </restriction>
+    </complexContent>
+       </complexType>
+EOF;
+test_schema($schema,'type="tns:testType"',array(123,123.5),"rpc","encoded",'',SOAP_USE_XSI_ARRAY_TYPE);
+echo "ok";
+?>
+--EXPECT--
+<?xml version="1.0" encoding="UTF-8"?>
+<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>
+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 (executable)
index 0000000..34c4c76
--- /dev/null
@@ -0,0 +1,31 @@
+--TEST--
+SOAP XML Schema 82: SOAP 1.1 Array with SOAP_USE_XSI_ARRAY_TYPE (second way)
+--SKIPIF--
+<?php require_once('skipif.inc'); ?>
+--FILE--
+<?php
+include "test_schema.inc";
+$schema = <<<EOF
+       <complexType name="testType">
+               <complexContent>
+                       <restriction base="SOAP-ENC:Array">
+                               <all>
+                                       <element name="x_item" type="int" maxOccurs="unbounded"/>
+                   </all>
+       </restriction>
+    </complexContent>
+       </complexType>
+EOF;
+test_schema($schema,'type="tns:testType"',array(123,123.5),"rpc","encoded",'',SOAP_USE_XSI_ARRAY_TYPE);
+echo "ok";
+?>
+--EXPECT--
+<?xml version="1.0" encoding="UTF-8"?>
+<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>
+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 (executable)
index 0000000..854c4f9
--- /dev/null
@@ -0,0 +1,30 @@
+--TEST--
+SOAP XML Schema 83: SOAP 1.2 Array with SOAP_USE_XSI_ARRAY_TYPE
+--SKIPIF--
+<?php require_once('skipif.inc'); ?>
+--FILE--
+<?php
+include "test_schema.inc";
+$schema = <<<EOF
+       <complexType name="testType">
+               <complexContent>
+                       <restriction base="enc12:Array" xmlns:enc12="http://www.w3.org/2003/05/soap-encoding">
+           <attribute ref="enc12:itemType" wsdl:itemType="int"/>
+           <attribute ref="enc12:arraySize" wsdl:arraySize="*"/>
+       </restriction>
+    </complexContent>
+       </complexType>
+EOF;
+test_schema($schema,'type="tns:testType"',array(123,123.5),"rpc","encoded",'',SOAP_USE_XSI_ARRAY_TYPE);
+echo "ok";
+?>
+--EXPECT--
+<?xml version="1.0" encoding="UTF-8"?>
+<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>
+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 (executable)
index 0000000..94a9551
--- /dev/null
@@ -0,0 +1,31 @@
+--TEST--
+SOAP XML Schema 84: SOAP 1.2 Array with SOAP_USE_XSI_ARRAY_TYPE (second way)
+--SKIPIF--
+<?php require_once('skipif.inc'); ?>
+--FILE--
+<?php
+include "test_schema.inc";
+$schema = <<<EOF
+       <complexType name="testType">
+               <complexContent>
+                       <restriction base="enc12:Array" xmlns:enc12="http://www.w3.org/2003/05/soap-encoding">
+                               <all>
+                                       <element name="x_item" type="int" maxOccurs="unbounded"/>
+                   </all>
+       </restriction>
+    </complexContent>
+       </complexType>
+EOF;
+test_schema($schema,'type="tns:testType"',array(123,123.5),"rpc","encoded",'',SOAP_USE_XSI_ARRAY_TYPE);
+echo "ok";
+?>
+--EXPECT--
+<?xml version="1.0" encoding="UTF-8"?>
+<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>
+array(2) {
+  [0]=>
+  int(123)
+  [1]=>
+  int(123)
+}
+ok
index 63214f23f0d0357c8fae2e6e7457f245c15b63a3..2072f150ade440d68176fdde90f6db6be608de87 100644 (file)
@@ -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  = <<<EOF
 <definitions name="InteropTest"
@@ -55,8 +55,8 @@ EOF;
   @fwrite($f,$wsdl);
   fclose($f);
   ini_set("soap.wsdl_cache_enabled",0);
-  $x = new SoapClient($fname, array("trace"=>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);