php - Zend SOAP: Change the default array element name "item" to class name of complex type in WSDL -
this question might asked, hard search for, can not find it. plus not easy ask.
i'm using zend soap's autodiscover re-create our old soap interface (because of switching micro services , re-working everything).
so far it's working charm. have 1 problem in recreating soap response of services when using lists/arrays.
the old response xml of soap request looked this. contains 2 <smsentry>s in <smsentries> list.
<soap-env:envelope> <soap-env:body> <ns1:getsmsbytimespanresult> <amountofentries>2</amountofentries> <smsentries> <smsentry></smsentry> <smsentry></smsentry> </smsentries> </ns1:getsmsbytimespanresult> </soap-env:body> </soap-env:envelope> but recreated response looks this. contains 2 <item>s of type smsentry in <smsentries> list.
<soap-env:envelope> <soap-env:body> <ns1:getsmsbytimespanresponse> <return xsi:type="ns1:getsmsbytimespanresponse"> <amountofentries xsi:type="xsd:int">2</amountofentries> <smsentries soap-enc:arraytype="ns1:smsentry[2]" xsi:type="ns1:arrayofsmsentry"> <item xsi:type="ns1:smsentry"></item> <item xsi:type="ns1:smsentry"></item> </smsentries> <dataex xsi:nil="true"/> </return> </ns1:getsmsbytimespanresponse> </soap-env:body> </soap-env:envelope> i have no control of clients. might checking smsentry comparing string. want use class name smsentry xml-tag name.
second, leave out additional, wrapping everything, <return> tag.
i using autodiscover this:
use zend\soap\autodiscover; use zend\soap\wsdl\complextypestrategy\arrayoftypecomplex; $autodiscover = new autodiscover(new arrayoftypecomplex()); $autodiscover->setclass(new standard($sm)); the getsmsbytimespanresponse defined this:
standard.php
/** * class getsmsbytimespanresponse * * @package lgxservicemanager\service */ class getsmsbytimespanresponse { /** * @var int */ public $amountofentries; /** * @var \lgxservicemanager\service\smsentry[] */ public $smsentries; } /** * class smsentry * * @package lgxservicemanager\service */ class smsentry { } does have idea on how this?
i found code in library\zend\soap\wsdl\complextypestrategy\arrayoftypesequence.php:122 _addsequencetype() method setting attribute hardcoded:
$element->setattribute('name', 'item'); but in type "sequence" not type "complex" i'm using...
thank in advance, philipp
\edit
oh man... discovered structure don't know how create zend soap's autodiscover...
<mainmember1>serialnumber</mainmember1> <mainmember2>nameofproduct</mainmember2> <mainmember3>000000-000-0</mainmember3> <rules> <ruleentry> <singlevalue>allow</singlevalue> <resourcelist> <name>generic</name> <resourceentry>[...]</resourceentry> <resourceentry>[...]</resourceentry> <resourceentry>[...]</resourceentry> </resourcelist> <resourcelist> <name>default</name> <resourceentry>[...]</resourceentry> <resourceentry>[...]</resourceentry> <resourceentry>[...]</resourceentry> </resourcelist> </ruleentry> </rules> as can see, there <singlevalue> inside <ruleentry> multiple <resourcelist>s. same structure used inside resource lists: 1 <name> , multiple <resourceentry>...
is possible handle autodiscover?
for still having above problem: default response of stdclass() this:
$array = ['lets', 'test', 'it']; $response = new stdclass(); $response->results = $array; will like:
<return xsi:type="soap-enc:struct"> <results soap-enc:arraytype="xsd:string[3]" xsi:type="soap-enc:array"> <item xsi:type="xsd:string">lets</item> <item xsi:type="xsd:string">test</item> <item xsi:type="xsd:string">it</item> </results> </return> what can - can change array arrayobject():
$array = ['lets', 'test', 'it']; $response = new stdclass(); $response->results = new arrayobject(); foreach($array $item) { $response->results->append($item); } which return:
<return xsi:type="soap-enc:struct"> <results xsi:type="soap-enc:struct"> <bogus xsi:type="xsd:string">lets</bogus> <bogus xsi:type="xsd:string">test</bogus> <bogus xsi:type="xsd:string">it</bogus> </results> </return> and icing on cake:
$array = ['lets', 'test', 'it']; $response = new stdclass(); $response->results = new arrayobject(); foreach($array $item) { $soapvar = new soapvar($item,xsd_string,null,null,'result'); $response->results->append($soapvar); } it return:
<return xsi:type="soap-enc:struct"> <results xsi:type="soap-enc:struct"> <result xsi:type="xsd:string">lets</result> <result xsi:type="xsd:string">test</result> <result xsi:type="xsd:string">it</result> </results> </return> as can see fifth argument tells key of xml element. need aware of second argument too, becaouse tells type of variable. can find more here: https://secure.php.net/manual/en/class.soapvar.php
Comments
Post a Comment