php – 包装文档/文字数组的示例

发布时间:2022-04-30 发布网站:脚本宝典
脚本宝典收集整理的这篇文章主要介绍了php – 包装文档/文字数组的示例脚本宝典觉得挺不错的,现在分享给大家,也给大家做个参考。
我在查找包装文档/文字样式中的简单数组的实例时遇到了麻烦.

考虑一个PHP函数,它生成一个最大计数的数组.

/**
 * @param int $max
 * @return string[] $count
 */
public function countTo($max)
{
    $array = array();
    for ($i = 0; $i < $max; $i++) {
        $array[] = 'Number: ' . ($i + 1);
    }
    return $array;
}

为此生成的WSDL类型是:

<xsd:complexTyPE name="countTo">
  <xsd:sequence>
    <xsd:element name="max" type="xsd:int"/>
  </xsd:sequence>
</xsd:complexType>
<xsd:element name="countTo" nillable="true" type="ns:countTo"/>
<xsd:complexType name="ArrayOfcount">
  <xsd:sequence>
    <xsd:element minOccurs="0" maxOccurs="unbounded" name="count" nillable="true" type="xsd:string"/>
  </xsd:sequence>
</xsd:complexType>
<xsd:complexType name="countToResponse">
  <xsd:sequence>
    <xsd:element name="count" type="ns:ArrayOfCount"/>
  </xsd:sequence>
</xsd:complexType>
<xsd:element name="countToResponse" nillable="true" type="ns:countToResponse"/>

正文中的请求看起来像:

<ns1:countTo>
  <;max>5</max>
</ns1:countTo>

但是响应是什么样的,什么是惯例?

目前,SOApServer正在生成

<ns1:countToResponse>
  <count>
    <count>Number: 1</count>
    <count>Number: 2</count>
    <count>Number: 3</count>
    <count>Number: 4</count>
    <count>Number: 5</count>
  </count>
</ns1:countToResponse>

我不确定嵌套计数元素.也许这应该是项目(并且需要更新WSDL才能实现).

<ns1:countToResponse>
  <count>
    <ITem>Number: 1</item>
    <item>Number: 2</item>
    <item>Number: 3</item>
    <item>Number: 4</item>
    <item>Number: 5</item>
  </count>
</ns1:countToResponse>
对此没有任何约定.当您有一个项目数组来命名集合项时,有时会很方便.但是因为你的元素被命名为count会有点困难,因为计数不是一个公认的答案.您可以选择结果,但这只适用于它也是唯一的容器元素,如您的示例所示.
<xsd:complexType name="countToResponse">
  <xsd:sequence>
    <xsd:element name="result" type="ns:ArrayOfCount"/>
  </xsd:sequence>
</xsd:complexType>

脚本宝典总结

以上是脚本宝典为你收集整理的php – 包装文档/文字数组的示例全部内容,希望文章能够帮你解决php – 包装文档/文字数组的示例所遇到的问题。

如果觉得脚本宝典网站内容还不错,欢迎将脚本宝典推荐好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。