From: Dmitry Stogov Date: Thu, 27 Dec 2007 13:10:32 +0000 (+0000) Subject: Added ability to use SplArrays instead of plain arrays in ext/soap. (Joshua Reese... X-Git-Tag: RELEASE_2_0_0a1~1098 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=eb572d00936aee2041b1ea5e760baeb6155007b8;p=php Added ability to use SplArrays instead of plain arrays in ext/soap. (Joshua Reese, Dmitry) --- diff --git a/ext/soap/php_encoding.c b/ext/soap/php_encoding.c index 7a5b16adac..3f7c728ad9 100644 --- a/ext/soap/php_encoding.c +++ b/ext/soap/php_encoding.c @@ -27,6 +27,10 @@ #include #include "zend_strtod.h" +#ifdef HAVE_SPL +# include "ext/spl/spl_array.h" +#endif + /* zval type decode */ static zval *to_zval_double(encodeTypePtr type, xmlNodePtr data); static zval *to_zval_long(encodeTypePtr type, xmlNodePtr data); @@ -2172,7 +2176,9 @@ static xmlNodePtr to_xml_array(encodeTypePtr type, zval *data, int style, xmlNod int dimension = 1; int* dims; int soap_version; - +#ifdef HAVE_SPL + zval *array_copy = NULL; +#endif TSRMLS_FETCH(); soap_version = SOAP_GLOBAL(soap_version); @@ -2192,6 +2198,18 @@ static xmlNodePtr to_xml_array(encodeTypePtr type, zval *data, int style, xmlNod return xmlParam; } +#ifdef HAVE_SPL + if (Z_TYPE_P(data) == IS_OBJECT && (instanceof_function(Z_OBJCE_P(data), spl_ce_ArrayObject TSRMLS_CC) || instanceof_function(Z_OBJCE_P(data), spl_ce_ArrayIterator TSRMLS_CC))) { + zval getArray; + + ZVAL_STRING(&getArray, "getArrayCopy", 0); + call_user_function_ex(NULL, &data, &getArray, &array_copy, 0, 0, 0, NULL TSRMLS_CC); + if (Z_TYPE_P(array_copy) == IS_ARRAY) { + data = array_copy; + } + } +#endif + if (Z_TYPE_P(data) == IS_ARRAY) { sdlAttributePtr *arrayType; sdlExtraAttributePtr *ext; @@ -2369,6 +2387,13 @@ static xmlNodePtr to_xml_array(encodeTypePtr type, zval *data, int style, xmlNod set_ns_and_type(xmlParam, type); } } + +#ifdef HAVE_SPL + if (array_copy) { + zval_ptr_dtor(&array_copy); + } +#endif + return xmlParam; } diff --git a/ext/soap/tests/server030.phpt b/ext/soap/tests/server030.phpt new file mode 100644 index 0000000000..fa59bc77ad --- /dev/null +++ b/ext/soap/tests/server030.phpt @@ -0,0 +1,51 @@ +--TEST-- +SOAP Server 30: Handling classes which extend the SPL ArrayObject or ArrayIterator as arrays in wsdl mode +--SKIPIF-- + +--FILE-- +text = 'text'.$i; + + $items[] = $item; + } + + return $items; + } +} + +$server = new SoapServer(dirname(__FILE__)."/server030.wsdl"); +$server->setClass('handlerClass'); + +$HTTP_RAW_POST_DATA = << + + + + + +EOF; + +$server->handle($HTTP_RAW_POST_DATA); +echo "ok\n"; +?> +--EXPECT-- + +text0text1text2text3text4text5text6text7text8text9 +ok diff --git a/ext/soap/tests/server030.wsdl b/ext/soap/tests/server030.wsdl new file mode 100644 index 0000000000..2139c78d96 --- /dev/null +++ b/ext/soap/tests/server030.wsdl @@ -0,0 +1,59 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +