能否将元素名称映射到php类(SoapClient)?

3
使用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
        (
            ...
        )
)

这几乎使类映射功能失去了意义。

任何帮助将不胜感激。

谢谢。

1个回答

5

我误解了类型的定义。

类型在以下示例中不是R1Out:

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

实际上,这是指类型
$options['classmap'] = array('M1Response' => 'MyPHPClassResponse');
$client = new SoapClient('test.wsdl', $options);
$client->__getTypes();

检查__getTypes()的输出结果,可以发现M1Response元素确实与一种类型相关联:

struct M1Response {
    R1Out N1Response;
}

因此,答案就是(如上所述):
$options['classmap'] = array('M1Response' => 'MyPHPClassResponse');

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接