dmitry Thu Dec 27 13:10:32 2007 UTC Modified files: /php-src/ext/soap php_encoding.c /php-src/ext/soap/tests server030.phpt server030.wsdl Log: Added ability to use SplArrays instead of plain arrays in ext/soap. (Joshua Reese, Dmitry) http://cvs.php.net/viewvc.cgi/php-src/ext/soap/php_encoding.c?r1=1.165&r2=1.166&diff_format=u Index: php-src/ext/soap/php_encoding.c diff -u php-src/ext/soap/php_encoding.c:1.165 php-src/ext/soap/php_encoding.c:1.166 --- php-src/ext/soap/php_encoding.c:1.165 Wed Oct 17 12:09:14 2007 +++ php-src/ext/soap/php_encoding.c Thu Dec 27 13:10:32 2007 @@ -17,7 +17,7 @@ | Dmitry Stogov <[EMAIL PROTECTED]> | +----------------------------------------------------------------------+ */ -/* $Id: php_encoding.c,v 1.165 2007/10/17 12:09:14 dmitry Exp $ */ +/* $Id: php_encoding.c,v 1.166 2007/12/27 13:10:32 dmitry Exp $ */ #include <time.h> @@ -27,6 +27,10 @@ #include <libxml/parserInternals.h> #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 @@ 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 @@ 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 @@ set_ns_and_type(xmlParam, type); } } + +#ifdef HAVE_SPL + if (array_copy) { + zval_ptr_dtor(&array_copy); + } +#endif + return xmlParam; } http://cvs.php.net/viewvc.cgi/php-src/ext/soap/tests/server030.phpt?r1=1.1&r2=1.2&diff_format=u Index: php-src/ext/soap/tests/server030.phpt diff -u /dev/null php-src/ext/soap/tests/server030.phpt:1.2 --- /dev/null Thu Dec 27 13:10:32 2007 +++ php-src/ext/soap/tests/server030.phpt Thu Dec 27 13:10:32 2007 @@ -0,0 +1,51 @@ +--TEST-- +SOAP Server 30: Handling classes which extend the SPL ArrayObject or ArrayIterator as arrays in wsdl mode +--SKIPIF-- +<?php require_once('skipif.inc'); ?> +--FILE-- +<?php +class ItemArray extends ArrayObject { + +} + +class Item { + public $text; +} + +class handlerClass { + public function getItems() + { + $items = new ItemArray(array()); + + for ($i = 0; $i < 10; $i++) { + $item = new Item(); + $item->text = 'text'.$i; + + $items[] = $item; + } + + return $items; + } +} + +$server = new SoapServer(dirname(__FILE__)."/server030.wsdl"); +$server->setClass('handlerClass'); + +$HTTP_RAW_POST_DATA = <<<EOF +<?xml version="1.0" encoding="ISO-8859-1"?> +<SOAP-ENV:Envelope + SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" + xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"> + <SOAP-ENV:Body> + <getItems/> + </SOAP-ENV:Body> +</SOAP-ENV:Envelope> +EOF; + +$server->handle($HTTP_RAW_POST_DATA); +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://testuri.org" xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"><SOAP-ENV:Body><ns1:getItemsResponse><getItemsReturn SOAP-ENC:arrayType="ns1:Item[10]" xsi:type="ns1:ItemArray"><item xsi:type="ns1:Item"><text xsi:type="xsd:string">text0</text></item><item xsi:type="ns1:Item"><text xsi:type="xsd:string">text1</text></item><item xsi:type="ns1:Item"><text xsi:type="xsd:string">text2</text></item><item xsi:type="ns1:Item"><text xsi:type="xsd:string">text3</text></item><item xsi:type="ns1:Item"><text xsi:type="xsd:string">text4</text></item><item xsi:type="ns1:Item"><text xsi:type="xsd:string">text5</text></item><item xsi:type="ns1:Item"><text xsi:type="xsd:string">text6</text></item><item xsi:type="ns1:Item"><text! xsi:type="xsd:string">text7</text></item><item xsi:type="ns1:Item"><text xsi:type="xsd:string">text8</text></item><item xsi:type="ns1:Item"><text xsi:type="xsd:string">text9</text></item></getItemsReturn></ns1:getItemsResponse></SOAP-ENV:Body></SOAP-ENV:Envelope> +ok http://cvs.php.net/viewvc.cgi/php-src/ext/soap/tests/server030.wsdl?r1=1.1&r2=1.2&diff_format=u Index: php-src/ext/soap/tests/server030.wsdl diff -u /dev/null php-src/ext/soap/tests/server030.wsdl:1.2 --- /dev/null Thu Dec 27 13:10:32 2007 +++ php-src/ext/soap/tests/server030.wsdl Thu Dec 27 13:10:32 2007 @@ -0,0 +1,59 @@ +<?xml version='1.0' encoding='UTF-8'?> +<definitions + xmlns:xsd="http://www.w3.org/2001/XMLSchema" + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/" + xmlns:si="http://soapinterop.org/xsd" + xmlns:tns="http://testuri.org" + xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" + xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" + xmlns="http://schemas.xmlsoap.org/wsdl/" + targetNamespace="http://testuri.org"> + + <types> + <xsd:schema xmlns="http://www.w3.org/2001/XMLSchema" targetNamespace="http://testuri.org"> + <xsd:complexType name="ItemArray"> + <xsd:complexContent> + <xsd:extension base="SOAP-ENC:Array"> + <xsd:attribute ref="SOAP-ENC:arrayType" wsdl:arrayType="tns:Item[]"/> + </xsd:extension> + </xsd:complexContent> + </xsd:complexType> + <xsd:complexType name="Item"> + <xsd:sequence> + <xsd:element name="text" type="string"/> + </xsd:sequence> + </xsd:complexType> + </xsd:schema> + </types> + + <message name="getItems"/> + <message name="getItemsResponse"> + <part name="getItemsReturn" type="tns:ItemArray"/> + </message> + + <portType name="TestServicePortType"> + <operation name="getItems"> + <input message="tns:getItems"/> + <output message="tns:getItemsResponse"/> + </operation> + </portType> + + <binding name="TestServiceBinding" type="tns:TestServicePortType"> + <soap:binding style="rpc" transport="http://schemas.xmlsoap.org/soap/http"/> + <operation name="getItems"> + <soap:operation soapAction="http://testuri.orgTestServiceAction"/> + <input/> + <output> + <soap:body namespace="http://testuri.org" use="encoded" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"/> + </output> + </operation> + </binding> + + <service name="TestServiceService"> + <port name="TestServicePort" binding="tns:TestServiceBinding"> + <soap:address location="http://linuxsrv.home/~dmitry/soap/soap_server.php"/> + </port> + </service> + +</definitions>
-- PHP CVS Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php