【问题标题】:Is it possible to map element name to php class (SoapClient)是否可以将元素名称映射到 php 类(SoapClient)
【发布时间】:2023-03-18 05:49:01
【问题描述】:

使用 SoapClient,是否可以将元素名称(而不是类型)映射到 php 类?

在php手册中:

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

classmap 是这样定义的:

classmap 选项可用于将某些 WSDL 类型映射到 PHP 类。此选项必须是一个数组,其中 WSDL 类型作为键,PHP 类的名称作为值。

如果元素没有类型,是否可以映射?

例如。

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

即。我想将元素 M1Response 映射到一个 php 类

我可以将N1Response映射到一个php类,但是响应是这样的:

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

这几乎违背了类映射功能的目的。

任何帮助将不胜感激。

谢谢

【问题讨论】:

    标签: php xml wsdl soap-client


    【解决方案1】:

    所以我误解了types的定义

    type 在以下示例中是不是 R1Out

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

    其实就是这个type:

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

    检查__getTypes() 的输出发现确实有一个类型与 M1Response 元素相关联:

    struct M1Response {
        R1Out N1Response;
    }
    

    所以答案是(如上所述):

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-02-24
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-10-14
      • 2021-08-11
      • 1970-01-01
      相关资源
      最近更新 更多