WsdlToPhp / PackageGenerator

Generates a PHP SDK based on a WSDL, simple and powerful, WSDL to PHP
https://providr.io
MIT License
428 stars 73 forks source link

question or bug #235

Closed myname1614 closed 3 years ago

myname1614 commented 3 years ago

wsdl: https://econnector.elit.cz/InterCompany-1.75.0/BuyerService?wsdl

method getNumOfOrderLines has definitions:

<Envelope xmlns="http://schemas.xmlsoap.org/soap/envelope/">
    <Body>
        <getNumOfOrderLines xmlns="http://buyer.elit.cz/">
            <!-- Optional -->
            <arg0 xmlns="">
                <CompanyName>[string?]</CompanyName>
                <Login>[string?]</Login>
                <Password>[string?]</Password>
                <RequestId>[string?]</RequestId>
                <applicationId>[string?]</applicationId>
                <OrderNo>[string?]</OrderNo>
                <ReasonCodeFilter>[string?]</ReasonCodeFilter>
                <StatusShippedFilter>[boolean]</StatusShippedFilter>
                <StatusUnshippedFilter>[boolean]</StatusUnshippedFilter>
                <ItemFilter>[string?]</ItemFilter>
            </arg0>
        </getNumOfOrderLines>
    </Body>
</Envelope>

but generator created classes:

class RequestGetNumOfOrderLines extends RequestBase
{
....
    public function __construct($orderNo = null, $reasonCodeFilter = null, $statusShippedFilter = null, $statusUnshippedFilter = null, $itemFilter = null)
    {
        $this
            ->setOrderNo($orderNo)
            ->setReasonCodeFilter($reasonCodeFilter)
            ->setStatusShippedFilter($statusShippedFilter)
            ->setStatusUnshippedFilter($statusUnshippedFilter)
            ->setItemFilter($itemFilter);
    }
....    
 }   
class RequestBase extends AbstractStructBase
{
  public function __construct($companyName = null, $login = null, $password = null, $requestId = null, $applicationId = null)
  {
  ...
  }
....
}    

class GetNumOfOrderLines extends AbstractStructBase
{
...
    public function __construct(\common\components\Elit\soap\StructType\RequestGetNumOfOrderLines $arg0 = null)
    {
        $this
            ->setArg0($arg0);
    }    
....    
}    

my question. how can I create a request correctly with all params?

i tried to do like this:

        $arg0 = new \common\components\Elit\soap\StructType\RequestGetNumOfOrderLines('orderNo', 'reasonCodeFilter', ....);
        $params = new \common\components\Elit\soap\StructType\GetNumOfOrderLines($arg0);

but I did not understand how to add a login, password here.

thanks!


P.S. in a similar case, no problem. we have constructor params:

class GetNumOfCrMemos extends AbstractStructBase
{
  public function __construct($company = null, $login = null, $password = null, $open = null, $closed = null, $overdue = null)
}
<Envelope xmlns="http://schemas.xmlsoap.org/soap/envelope/">
    <Body>
        <getNumOfCrMemos xmlns="http://buyer.elit.cz/">
            <company xmlns="">[string?]</company>
            <login xmlns="">[string?]</login>
            <password xmlns="">[string?]</password>
            <open xmlns="">[boolean]</open>
            <closed xmlns="">[boolean]</closed>
            <overdue xmlns="">[boolean]</overdue>
        </getNumOfCrMemos>
    </Body>
</Envelope>
mikaelcom commented 3 years ago

Actually, the first XML you're showing is the SoapUI request, am I wrong? Which is the SoapUI-generated XML request to send, not the actual definition of requestGetNumOfOrderLines.

The getNumOfOrderLines is defined such as:

<xs:complexType name="getNumOfOrderLines">
 <xs:sequence>
  <xs:element name="arg0" type="tns:requestGetNumOfOrderLines" minOccurs="0"/>
 </xs:sequence>
</xs:complexType>
<xs:complexType name="requestGetNumOfOrderLines">
 <xs:complexContent>
  <xs:extension base="tns:requestBase">
   <xs:sequence>
    <xs:element name="OrderNo" type="xs:string" minOccurs="0"/>
    <xs:element name="ReasonCodeFilter" type="xs:string" minOccurs="0"/>
    <xs:element name="StatusShippedFilter" type="xs:boolean"/>
    <xs:element name="StatusUnshippedFilter" type="xs:boolean"/>
    <xs:element name="ItemFilter" type="xs:string" minOccurs="0"/>
   </xs:sequence>
  </xs:extension>
 </xs:complexContent>
</xs:complexType>

And requestBase is defined as below:

<xs:complexType name="requestBase">
 <xs:sequence>
  <xs:element name="CompanyName" type="xs:string" minOccurs="0"/>
  <xs:element name="Login" type="xs:string" minOccurs="0"/>
  <xs:element name="Password" type="xs:string" minOccurs="0"/>
  <xs:element name="RequestId" type="xs:string" minOccurs="0"/>
  <xs:element name="applicationId" type="xs:string" minOccurs="0"/>
 </xs:sequence>
</xs:complexType>

So, with PHP you should be able to do as below:

$request = new RequestGetNumOfOrderLines();
$request
    ->setOrderNo()
    ->setReasonCodeFilter()
    ->setStatusShippedFilter()
    ->setStatusUnshippedFilter()
    ->setItemFilter()
    // RequestGetNumOfOrderLines extends the RequestBase class,
    // these setters are within the generated RequestBase class
    ->setCompanyName()
    ->setLogin()
    ->setPassword()
    ->setRequestId()
    ->setapplicationId();

As the RequestGetNumOfOrderLines extends the Requestbase class which is defined with its own properties along with their fluent setters.

myname1614 commented 3 years ago

yes it will work. I can even wrap this all in my extend class. but we created a kit of helpers :-) I wanted to avoid manually calling hundreds of setters Maybe you need to provide for some additional functionality? Something similar to this:

class RequestGetNumOfOrderLines 
{

  //auto generated if has parent
  public function initBase(RequestBase $obj) 
  {
     //to iterate obj props & batch assigns     
  }

}

thanks. sorry for my googletranslate english )

mikaelcom commented 3 years ago

You have indeed the static __set_state(array $properties) method which takes care of calling the setter for each property.

Is this what you're looking for?

myname1614 commented 3 years ago

looks good. I will try it. Thanks.