From: Dmitry Stogov Date: Thu, 27 Dec 2007 13:10:20 +0000 (+0000) Subject: Added ability to use SplArrays instead of plain arrays in ext/soap. (Joshua Reese... X-Git-Tag: RELEASE_1_3_1~464 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=964b8bb30dc5e9fb0b9110ed8146e13cc0795cc1;p=php Added ability to use SplArrays instead of plain arrays in ext/soap. (Joshua Reese, Dmitry) --- diff --git a/NEWS b/NEWS index 509a7cd118..e68a144e82 100644 --- a/NEWS +++ b/NEWS @@ -1,6 +1,8 @@ PHP NEWS ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||| ?? ??? 20??, PHP 5.3.0 +- Added ability to use SplArrays instead of plain arrays in ext/soap. + (Joshua Reese, Dmitry) - Added "?:" operator. (Marcus) - Added stream_supports_lock() function. (Benjamin Schulz) - Added msg_queue_exists() function. (Benjamin Schulz) diff --git a/ext/soap/php_encoding.c b/ext/soap/php_encoding.c index df6b9cd6bd..d7dea05396 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); @@ -2238,7 +2242,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); @@ -2258,6 +2264,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; @@ -2435,6 +2453,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 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +