加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 站长学院 > PHP教程 > 正文

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

发布时间:2020-12-13 13:10:40 所属栏目:PHP教程 来源:网络整理
导读:我在查找包装文档/文字样式中的简单数组的实例时遇到了麻烦. 考虑一个PHP函数,它生成一个最大计数的数组. /** * @param int $max * @return string[] $count */public function countTo($max){ $array = array(); for ($i = 0; $i $max; $i++) { $array[] =
我在查找包装文档/文字样式中的简单数组的实例时遇到了麻烦.

考虑一个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>

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读