shereifhawary
shereifhawary

Reputation: 461

convert SOAP struct to php class

how can i convert SOAP struct like

 <wsdl:types>
  <xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema" targetNamespace="http://www.example.org/service1/">
   <xsd:complexType name="requestDescriptor">
    <xsd:all>
     <xsd:element name="x" type="xsd:string"></xsd:element>
     <xsd:element name="xx" type="xsd:string"></xsd:element>
     <xsd:element name="xxx" type="xsd:int"></xsd:element>
     <xsd:element name="xxxx" type="xsd:string"></xsd:element>

     <xsd:element name="xxxxx" type="xsd:string"></xsd:element>
    </xsd:all>
   </xsd:complexType>
  </xsd:schema>
 </wsdl:types>

to a php object if i call

$soapC = new SoapClient("http://192.168.1.3/forga/tests/vodSoapWS.wsdl");
$ret = $soapC->__getTypes();
$x = $ret[0];

the problem is $x type is string how can i used it as an object ??

Upvotes: 0

Views: 3813

Answers (2)

Benoit
Benoit

Reputation: 3598

Not a proper ready to use answer, but take a look at __get and __set "magic" methods overloading.

Implementing them in your RequestDescriptor class (or in an upper level to generalize their use) will make you able to keep properties private or protected (as they should be in each object) and control which ones can be set. You can also use this to validate input before sending it to WS

In your answer's code, the risk to me is that you can call any var in the object potentially a real source of WS errors or worse, bugs (think of a misspelled property name, typo, etc)

Upvotes: 0

shereifhawary
shereifhawary

Reputation: 461

i get around this by creating class which carry the struct and call

$req = new RequestDescriptor();
        $req->x="ar";
        $req->xx="JSON";
        $req->xxx="xxxxx";
        $req->xxxx="-1";
        $req->xxxxx="xwwx11";
        $x = new SoapVar($req,SOAP_ENC_OBJECT);
        $ret = $soapC->function($x);

but is there is any dynamic way to do that ???

Upvotes: 2

Related Questions