简体   繁体   中英

Is it possible to map element name to php class (SoapClient)

Using SoapClient, is it possible to map an element name (as opposed to a type) to a php class?

In the php manual:

http://www.php.net/manual/en/soapclient.soapclient.php

classmap is defined thus:

The classmap option can be used to map some WSDL types to PHP classes. This option must be an array with WSDL types as keys and names of PHP classes as values.

Is it possible to map an element if it does not have a type?

eg.

<xsd:element name="M1Response">
  <xsd:complexType>
    <xsd:sequence>
      <xsd:element name="N1Response" type="bons0:R1Out"/>
    </xsd:sequence>
  </xsd:complexType>
</xsd:element>

ie. I want to map the element M1Response to a php class

I can map N1Response to a php class, but the response is like so:

stdClass Object
(
    [N1Response] => MyPHPClassResponse Object
        (
            ...
        )
)

which almost defeats the purpose of the classmap functionality.

Any help would be appreciated.

Thanks

So I misunderstood the definition of types

type is not R1Out in the following example:

<xsd:element name="N1Response" type="bons0:R1Out"/>

it is in fact this type :

$options['classmap'] = array('M1Response' => 'MyPHPClassResponse');
$client = new SoapClient('test.wsdl', $options);
$client->__getTypes();

Examining the output of __getTypes() reveals that there is indeed a type associated with the M1Response element:

struct M1Response {
    R1Out N1Response;
}

And so the answer is (as mentioned above):

$options['classmap'] = array('M1Response' => 'MyPHPClassResponse');

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM